<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Non-const extern successfully compiles with const value"
href="https://bugs.llvm.org/show_bug.cgi?id=39069">39069</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Non-const extern successfully compiles with const value
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>6.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>dorooleg@yandex.ru
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>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.
<a href="http://www.skyfree.org/linux/references/ELF_Format.pdf">http://www.skyfree.org/linux/references/ELF_Format.pdf</a>
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?</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>