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++.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158689 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 4507b2f..a07f006 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -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">,
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index c9b1a69..49c8466 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -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) &&
diff --git a/test/Sema/inline.c b/test/Sema/inline.c
index 99df8b1..7f1815e 100644
--- a/test/Sema/inline.c
+++ b/test/Sema/inline.c
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// RUN: %clang_cc1 -fsyntax-only -verify -x c++ %s
 
 #if defined(INCLUDE)
 // -------
diff --git a/test/SemaCXX/inline.cpp b/test/SemaCXX/inline.cpp
index 9ef0229..6f3570e 100644
--- a/test/SemaCXX/inline.cpp
+++ b/test/SemaCXX/inline.cpp
@@ -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