[cfe-commits] r158531 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/Sema/inline.c

Jordan Rose jordan_rose at apple.com
Fri Jun 15 11:43:44 PDT 2012


On Jun 15, 2012, at 11:38 , Eli Friedman <eli.friedman at gmail.com> wrote:

> On Fri, Jun 15, 2012 at 11:19 AM, Jordan Rose <jordan_rose at apple.com> wrote:
>> Author: jrose
>> Date: Fri Jun 15 13:19:48 2012
>> New Revision: 158531
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=158531&view=rev
>> Log:
>> Warn when a static variable is referenced in a non-static inline function.
>> 
>> This is explicitly forbidden in C99 6.7.4p3. This is /not/ forbidden in C++,
>> probably because by default file-scope const/constexpr variables have internal
>> linkage, while functions have external linkage. There's also the issue of
>> anonymous namespaces to consider. Nevertheless, there should probably be a
>> similar warning, since the semantics of inlining a function that references
>> a variable with internal linkage do not seem well-defined.
> 
> The equivalent language in C++ is [basic.def.odr]p5.  It's a bit
> tricky to diagnose, though.
> 
> -Eli

Okay, it looks like it's basically the same restriction with an out for most const/constexpr variables. And since anonymous namespaces affect lookup, they work the same way as true internal linkage.

I'll go back and add this later. Thanks, Eli.

Jordan




More information about the cfe-commits mailing list