]> granicus.if.org Git - clang/commitdiff
Change -Winternal-linkage-in-inline from ExtWarn to Warning in C++.
authorJordan Rose <jordan_rose@apple.com>
Mon, 18 Jun 2012 23:58:49 +0000 (23:58 +0000)
committerJordan Rose <jordan_rose@apple.com>
Mon, 18 Jun 2012 23:58:49 +0000 (23:58 +0000)
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++.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158689 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/Sema/inline.c
test/SemaCXX/inline.cpp

index 4507b2fd572e5af2a0f493aae0032d1c37a9eec1..a07f00697b8104b90b05a2c632c611115f3c3ddd 100644 (file)
@@ -2997,11 +2997,14 @@ def warn_undefined_internal : Warning<
 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">,
index c9b1a694d0135b7e29dd2a08711a2e05363df341..49c84664fce0ba5fd906616d65a0a756de00fc29 100644 (file)
@@ -203,15 +203,23 @@ static void diagnoseUseOfInternalDeclInInlineFunction(Sema &S,
       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) &&
index 99df8b1106b8bdc5fbb4055c48720fb212b7fabc..7f1815e467da1ad77fa4df79eb6dd7021a620387 100644 (file)
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// RUN: %clang_cc1 -fsyntax-only -verify -x c++ %s
 
 #if defined(INCLUDE)
 // -------
index 9ef0229c990a0bd2e169028b2fb3a9836ac99799..6f3570e3ca099117005b2ed301faf37a6c835740 100644 (file)
@@ -95,14 +95,14 @@ inline int useStaticMainFile () {
   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