]> granicus.if.org Git - clang/commitdiff
Diagnose the use of "inline" on block-scope function declarations in
authorDouglas Gregor <dgregor@apple.com>
Fri, 6 Aug 2010 11:44:10 +0000 (11:44 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 6 Aug 2010 11:44:10 +0000 (11:44 +0000)
C++, from Andrea Nall!

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p3.cpp

index a917e2a74f30b4441702a7045256b20e5c1df8f9..3a85f4b8078460cef5344d07acf26113512b69c1 100644 (file)
@@ -1720,6 +1720,8 @@ def warn_redefinition_of_typedef : Warning<
   "redefinition of typedef %0 is invalid in C">,
   InGroup<DiagGroup<"typedef-redefinition"> >, DefaultError;
 
+def err_inline_declaration_block_scope : Error<
+  "inline declaration of %0 not allowed in block scope">;
 def err_static_non_static : Error<
   "static declaration of %0 follows non-static declaration">;
 def err_non_static_static : Error<
index 96839a542133855eb726dfe3e8334668964d25bf..f7e7928bbb08bb82b87e9bc6c35616c4f18b1eee 100644 (file)
@@ -3232,6 +3232,17 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
     }
   }
 
+  // C++ [dcl.fct.spec]p3:
+  //  The inline specifier shall not appear on a block scope function declaration.
+  if (isInline && !NewFD->isInvalidDecl() && getLangOptions().CPlusPlus) {
+    if (CurContext->isFunctionOrMethod()) {
+      // 'inline' is not allowed on block scope function declaration.
+      Diag(D.getDeclSpec().getInlineSpecLoc(), 
+           diag::err_inline_declaration_block_scope) << Name
+        << FixItHint::CreateRemoval(D.getDeclSpec().getInlineSpecLoc());
+    }
+  }
   // C++ [dcl.fct.spec]p6:
   //  The explicit specifier shall be used only in the declaration of a
   //  constructor or conversion function within its class definition; see 12.3.1
index 99a4f7aec4c8bfd76b0ecc4f3fbaeb1a1c2f722e..d7b9eff10a8086256be3f6e9193d493eb7509273 100644 (file)
@@ -1,11 +1,13 @@
 // RUN: %clang_cc1 -verify %s
-// XFAIL: *
 
-void f0(void) {
-  inline void f1(); // expected-error {{'inline' is not allowed on block scope function declaration}}
+void f0a(void) {
+   inline void f1(); // expected-error {{inline declaration of 'f1' not allowed in block scope}}
+}
+
+void f0b(void) {
+   void f1();
 }
 
 // FIXME: Add test for "If the inline specifier is used in a friend declaration,
 // that declaration shall be a definition or the function shall have previously
 // been declared inline.
-