[LLVMbugs] [Bug 22091] New: Add optional warning for namespace scoped constants with implicit internal linkage
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Sun Jan 4 10:44:45 PST 2015
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: unassignedclangbugs at nondot.org
Reporter: llvmbugs at contacts.eelis.net
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150104/db3d519c/attachment.html>
More information about the llvm-bugs
mailing list