[PATCH] D22113: C does not have inline variables

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rL275493: C does not have inline variables. (authored by probinson).

Changed prior to commit:
  https://reviews.llvm.org/D22113?vs=64053&id=64057#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22113

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

Index: cfe/trunk/test/SemaCXX/inline.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/inline.cpp
+++ cfe/trunk/test/SemaCXX/inline.cpp
@@ -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
Index: cfe/trunk/test/Sema/inline.c
===================================================================
--- cfe/trunk/test/Sema/inline.c
+++ cfe/trunk/test/Sema/inline.c
@@ -49,7 +49,7 @@
 #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}}
 
Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -6178,7 +6178,10 @@
   }
 
   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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22113.64057.patch
Type: text/x-patch
Size: 2192 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160714/de2fd022/attachment-0001.bin>


More information about the cfe-commits mailing list