From: Douglas Gregor Date: Fri, 6 Aug 2010 11:44:10 +0000 (+0000) Subject: Diagnose the use of "inline" on block-scope function declarations in X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed328c6129152f66771c3bed338a2e6e13e4e230;p=clang Diagnose the use of "inline" on block-scope function declarations in C++, from Andrea Nall! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110439 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index a917e2a74f..3a85f4b807 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1720,6 +1720,8 @@ def warn_redefinition_of_typedef : Warning< "redefinition of typedef %0 is invalid in C">, InGroup >, 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< diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 96839a5421..f7e7928bbb 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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 diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p3.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p3.cpp index 99a4f7aec4..d7b9eff10a 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p3.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p3.cpp @@ -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. -