[LLVMbugs] [Bug 5905] clang c++ should not allow a name with no linkage to declare an entity with linkage

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Mar 28 14:15:33 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=5905

Richard Smith <richard-llvm at metafoo.co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
                 CC|                            |richard-llvm at metafoo.co.uk
         Resolution|---                         |INVALID

--- Comment #5 from Richard Smith <richard-llvm at metafoo.co.uk> ---
The original code here is actually valid. Per C++ 3.5/8, "a type without
linkage shall not be used as the type of a variable [...] with external linkage
unless [...] the entity is not odr-used or is defined in the same translation
unit". In this case, the variable satisfies *both* of these criteria.

If we write:

union {
  int x;
  float y;
} extern anon; // not defined in this TU

int main() {
  return anon.x; // odr-used in this TU
}

... then clang issues a diagnostic:

<stdin>:4:10: warning: variable '<anonymous namespace>::anon' has internal
linkage but is not defined [-Wundefined-internal]
} extern anon;
         ^
<stdin>:7:10: note: used here
  return anon.x;
         ^

This still isn't quite right: we claim that 'anon' has internal linkage, but it
actually should have external linkage, and -pedantic-errors doesn't promote
this diagnostic to an error, but it's enough to be conforming.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140328/4a59b95e/attachment.html>


More information about the llvm-bugs mailing list