From f6fec8b923bb91567041d26560a4f0f9ac54c0ff Mon Sep 17 00:00:00 2001 From: Paul Robinson Date: Thu, 14 Jul 2016 22:22:58 +0000 Subject: [PATCH] C does not have inline variables. Add a few missing tests for related C++ diagnostics. Differential Revision: http://reviews.llvm.org/D22113 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275493 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 5 ++++- test/Sema/inline.c | 2 +- test/SemaCXX/inline.cpp | 13 +++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index c0ccbbf624..cedd21476c 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -6178,7 +6178,10 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, } 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 diff --git a/test/Sema/inline.c b/test/Sema/inline.c index 33b25206d7..eced058f8d 100644 --- a/test/Sema/inline.c +++ b/test/Sema/inline.c @@ -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}} diff --git a/test/SemaCXX/inline.cpp b/test/SemaCXX/inline.cpp index e569300faf..b20bc18d0a 100644 --- a/test/SemaCXX/inline.cpp +++ b/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 -- 2.40.0