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

            Bug ID: 22091
           Summary: Add optional warning for namespace scoped constants
                    with implicit internal linkage
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified

Created attachment 13627
  --> http://llvm.org/bugs/attachment.cgi?id=13627&action=edit
Rough implementation

It would be useful to have an optional warning about namespace-scoped constants
with implicit internal linkage, e.g.:

  t.cpp:1:11: warning: namespace-scoped constant implicitly has internal
linkage
  int const i = 3;
            ^

This can prevent bugs. In a library of mine I had a header x.hpp with:

  extern int const yada;

and x.cpp with:

  #include "x.hpp"
  int const yaba = 3;

I overlooked the typo, and so my users encountered "undefined reference to
yada" errors as soon as they tried to use yada.

The proposed warning would have caught the issue, because it would have spotted
yaba as having implicit internal linkage, which is always an anomaly in code of
mine, because whenever I /actually/ want a namespace scoped variable with
internal linkage, then for clarity and consistency I always say "static",
regardless of whether the variable happens to be const, to better express my
intent and not rely on the weird implicit-internal-linkage-for-constants
special case. :)

I'm attaching a patch that seems to work.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to