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

Jordan Rose jordan_rose at apple.com
Mon Jun 18 16:58:50 PDT 2012


Author: jrose
Date: Mon Jun 18 18:58:49 2012
New Revision: 158689

URL: http://llvm.org/viewvc/llvm-project?rev=158689&view=rev
Log:
Change -Winternal-linkage-in-inline from ExtWarn to Warning in C++.

Per post-commit review, it's not appropriate to use ExtWarn in C++, because
we can't prove that the inline function will actually be defined in more than
one place (and thus we can't prove that this violates the ODR).

This removes the warning entirely from uses in the main source file in C++.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Sema/inline.c
    cfe/trunk/test/SemaCXX/inline.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=158689&r1=158688&r2=158689&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jun 18 18:58:49 2012
@@ -2997,11 +2997,14 @@
 def note_used_here : Note<"used here">;
 
 def warn_internal_in_extern_inline : ExtWarn<
-  "%select{function|variable}0 %1 %select{has internal linkage|is in an anonymous"
-  " namespace}2 but is used in an inline %select{function|method}3 with"
-  " external linkage">,
+  "%select{function|variable}0 %1 has internal linkage but is used in an "
+  "inline function with external linkage">,
   InGroup<DiagGroup<"internal-linkage-in-inline"> >;
 def ext_internal_in_extern_inline : Extension<
+  "%select{function|variable}0 %1 has internal linkage but is used in an "
+  "inline function with external linkage">,
+  InGroup<DiagGroup<"internal-linkage-in-inline"> >;
+def warn_internal_in_extern_inline_cxx : Warning<
   "%select{function|variable}0 %1 %select{has internal linkage|is in an anonymous"
   " namespace}2 but is used in an inline %select{function|method}3 with"
   " external linkage">,

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=158689&r1=158688&r2=158689&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Jun 18 18:58:49 2012
@@ -203,15 +203,23 @@
       return;
 
   // Don't warn unless -pedantic is on if the inline function is in the main
-  // source file. These functions will most likely not be inlined into another
-  // translation unit, so they're effectively internal.
+  // source file, and in C++ don't warn at all, since the one-definition rule is
+  // still satisfied. This function will most likely not be inlined into
+  // another translation unit, so it's effectively internal.
   bool IsInMainFile = S.getSourceManager().isFromMainFile(Loc);
-  S.Diag(Loc, IsInMainFile ? diag::ext_internal_in_extern_inline
-                           : diag::warn_internal_in_extern_inline)
-    << (bool)VD
-    << D
-    << (UsedLinkage == UniqueExternalLinkage)
-    << isa<CXXMethodDecl>(Current);
+  if (S.getLangOpts().CPlusPlus) {
+    if (IsInMainFile)
+      return;
+
+    S.Diag(Loc, diag::warn_internal_in_extern_inline_cxx)
+      << (bool)VD << D
+      << (UsedLinkage == UniqueExternalLinkage)
+      << isa<CXXMethodDecl>(Current);
+  } else {
+    S.Diag(Loc, IsInMainFile ? diag::ext_internal_in_extern_inline
+                             : diag::warn_internal_in_extern_inline)
+      << (bool)VD << D;
+  }
 
   // Suggest "static" on the inline function, if possible.
   if (!isa<CXXMethodDecl>(Current) &&

Modified: cfe/trunk/test/Sema/inline.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/inline.c?rev=158689&r1=158688&r2=158689&view=diff
==============================================================================
--- cfe/trunk/test/Sema/inline.c (original)
+++ cfe/trunk/test/Sema/inline.c Mon Jun 18 18:58:49 2012
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// RUN: %clang_cc1 -fsyntax-only -verify -x c++ %s
 
 #if defined(INCLUDE)
 // -------

Modified: cfe/trunk/test/SemaCXX/inline.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/inline.cpp?rev=158689&r1=158688&r2=158689&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/inline.cpp (original)
+++ cfe/trunk/test/SemaCXX/inline.cpp Mon Jun 18 18:58:49 2012
@@ -95,14 +95,14 @@
   return staticVar; // no-warning
 }
 
-// Check that the warnings show up when explicitly requested.
+// Check that the warnings don't show up even when explicitly requested in C++.
 
 #pragma clang diagnostic push
 #pragma clang diagnostic warning "-Winternal-linkage-in-inline"
 
-inline int useStaticAgain () { // expected-note 2 {{use 'static' to give inline function 'useStaticAgain' internal linkage}}
-  anonFunction(); // expected-warning{{function 'anonFunction' is in an anonymous namespace but is used in an inline function with external linkage}}
-  return staticVar; // expected-warning{{variable 'staticVar' has internal linkage but is used in an inline function with external linkage}}
+inline int useStaticAgain () {
+  anonFunction(); // no-warning
+  return staticVar; // no-warning
 }
 
 #pragma clang diagnostic pop





More information about the cfe-commits mailing list