r275493 - C does not have inline variables.

Paul Robinson via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 14 15:22:58 PDT 2016


Author: probinson
Date: Thu Jul 14 17:22:58 2016
New Revision: 275493

URL: http://llvm.org/viewvc/llvm-project?rev=275493&view=rev
Log:
C does not have inline variables.
Add a few missing tests for related C++ diagnostics.

Differential Revision: http://reviews.llvm.org/D22113

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/inline.c
    cfe/trunk/test/SemaCXX/inline.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=275493&r1=275492&r2=275493&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jul 14 17:22:58 2016
@@ -6178,7 +6178,10 @@ Sema::ActOnVariableDeclarator(Scope *S,
   }
 
   if (D.getDeclSpec().isInlineSpecified()) {
-    if (CurContext->isFunctionOrMethod()) {
+    if (!getLangOpts().CPlusPlus) {
+      Diag(D.getDeclSpec().getInlineSpecLoc(), diag::err_inline_non_function)
+          << 0;
+    } else if (CurContext->isFunctionOrMethod()) {
       // 'inline' is not allowed on block scope variable declaration.
       Diag(D.getDeclSpec().getInlineSpecLoc(),
            diag::err_inline_declaration_block_scope) << Name

Modified: cfe/trunk/test/Sema/inline.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/inline.c?rev=275493&r1=275492&r2=275493&view=diff
==============================================================================
--- cfe/trunk/test/Sema/inline.c (original)
+++ cfe/trunk/test/Sema/inline.c Thu Jul 14 17:22:58 2016
@@ -49,7 +49,7 @@ inline int useConst () {
 #include "inline.c"
 
 // Check that we don't allow illegal uses of inline
-inline int a; // expected-warning{{inline variables are a C++1z extension}}
+inline int a; // expected-error{{'inline' can only appear on functions}}
 typedef inline int b; // expected-error{{'inline' can only appear on functions}}
 int d(inline int a); // expected-error{{'inline' can only appear on functions}}
 

Modified: cfe/trunk/test/SemaCXX/inline.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/inline.cpp?rev=275493&r1=275492&r2=275493&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/inline.cpp (original)
+++ cfe/trunk/test/SemaCXX/inline.cpp Thu Jul 14 17:22:58 2016
@@ -1,5 +1,18 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z %s -Wc++98-c++11-c++14-compat
 
 // Check that we don't allow illegal uses of inline
 // (checking C++-only constructs here)
 struct c {inline int a;}; // expected-error{{'inline' can only appear on functions}}
+
+void localVar() {
+  inline int a; // expected-error{{inline declaration of 'a' not allowed in block scope}}
+}
+
+// Check that we warn appropriately.
+#if __cplusplus <= 201402L
+inline int a; // expected-warning{{inline variables are a C++1z extension}}
+#else
+inline int a; // expected-warning{{inline variables are incompatible with C++ standards before C++1z}}
+#endif




More information about the cfe-commits mailing list