<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - Add optional warning for namespace scoped constants with implicit internal linkage"
   href="http://llvm.org/bugs/show_bug.cgi?id=22091">22091</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Add optional warning for namespace scoped constants with implicit internal linkage
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>llvmbugs@contacts.eelis.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=13627" name="attach_13627" title="Rough implementation">attachment 13627</a> <a href="attachment.cgi?id=13627&action=edit" title="Rough implementation">[details]</a></span>
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.</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>