Allow internal decls in inline functions if the function is in the main file.
This handles the very common case of people writing inline functions in their
main source files and not tagging them as inline. These cases should still
behave as the user intended. (The diagnostic is still emitted as an extension.)
I'm reworking this code anyway to account for C++'s equivalent restriction in
[basic.def.odr]p6, but this should get some bots back to green.
llvm-svn: 158666
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ae3a636..d995094 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -194,7 +194,13 @@
if (FunctionDecl *Current = getCurFunctionDecl()) {
if (Current->isInlined() && Current->getLinkage() > InternalLinkage) {
if (D->getLinkage() == InternalLinkage) {
- Diag(Loc, diag::warn_internal_in_extern_inline)
+ // We won't warn by default if the inline function is in the main
+ // source file; in these cases it is almost certain that the inlining
+ // will only occur in this file, even if there is an external
+ // declaration as well.
+ bool IsFromMainFile = getSourceManager().isFromMainFile(Loc);
+ Diag(Loc, IsFromMainFile ? diag::ext_internal_in_extern_inline
+ : diag::warn_internal_in_extern_inline)
<< !isa<FunctionDecl>(D) << D << isa<CXXMethodDecl>(Current);
// If the user didn't explicitly specify a storage class,