[cfe-commits] r110439 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p3.cpp
Douglas Gregor
dgregor at apple.com
Fri Aug 6 04:44:10 PDT 2010
Author: dgregor
Date: Fri Aug 6 06:44:10 2010
New Revision: 110439
URL: http://llvm.org/viewvc/llvm-project?rev=110439&view=rev
Log:
Diagnose the use of "inline" on block-scope function declarations in
C++, from Andrea Nall!
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p3.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=110439&r1=110438&r2=110439&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Aug 6 06:44:10 2010
@@ -1720,6 +1720,8 @@
"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<
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=110439&r1=110438&r2=110439&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Aug 6 06:44:10 2010
@@ -3232,6 +3232,17 @@
}
}
+ // 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
Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p3.cpp?rev=110439&r1=110438&r2=110439&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p3.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p3.cpp Fri Aug 6 06:44:10 2010
@@ -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.
-
More information about the cfe-commits
mailing list