https://bugs.llvm.org/show_bug.cgi?id=39069

            Bug ID: 39069
           Summary: Non-const extern successfully compiles with const
                    value
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangb...@nondot.org
          Reporter: doroo...@yandex.ru
                CC: dgre...@apple.com, llvm-bugs@lists.llvm.org

Hello guys!

For the code below, I get a link error for compiler msvc on Windows, but clang
on Linux successfully compiles, but when I run the executable I get segfault.
Is this behavior correct?

// a.cpp
extern int const A = 20;
---
// main.cpp
extern int A;
int main() {
  A = 30;
  return A; // 30
}

My research:
  1. I created two cpp files in one of them extern int A, and in another extern
int const A; Object files created from cpp were completely identical in byte.
  2. The NM utility for these files shows the same information as the following

Name     Value            Class  Type     Size             Line Section

A       ||GLOBAL|NOTYPE  ||    |UNDEF
main    |0000000000000000|GLOBAL|FUNC    |0000000000000014|    |.text
main.cpp|0000000000000000|LOCAL |FILE    |0000000000000000|    |ABS

  3. I opened the ELF format document and found no information about how to
differentiate between const and non-const.
http://www.skyfree.org/linux/references/ELF_Format.pdf

  4. At the same time msvc compiler is able to specify additional information
for extern const

Can anyone explain in more detail why this is so done, not the other way
around?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to