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
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">,
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) &&
// RUN: %clang_cc1 -fsyntax-only -verify %s
-// RUN: %clang_cc1 -fsyntax-only -verify -x c++ %s
#if defined(INCLUDE)
// -------
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