Re: [PATCH] D22113: C does not have inline variables
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=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 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 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D22113: C does not have inline variables
rsmith accepted this revision. rsmith added a comment. Thanks! https://reviews.llvm.org/D22113 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D22113: C does not have inline variables
probinson updated this revision to Diff 64053. probinson marked an inline comment as done. probinson added a comment. Reorder the checks. I didn't see any tests for the adjacent (C++) diagnostics so I added some. https://reviews.llvm.org/D22113 Files: lib/Sema/SemaDecl.cpp test/Sema/inline.c test/SemaCXX/inline.cpp Index: test/SemaCXX/inline.cpp === --- test/SemaCXX/inline.cpp +++ 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: test/Sema/inline.c === --- test/Sema/inline.c +++ 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: lib/Sema/SemaDecl.cpp === --- lib/Sema/SemaDecl.cpp +++ 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 Index: test/SemaCXX/inline.cpp === --- test/SemaCXX/inline.cpp +++ 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: test/Sema/inline.c === --- test/Sema/inline.c +++ 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: lib/Sema/SemaDecl.cpp === --- lib/Sema/SemaDecl.cpp +++ 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 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D22113: C does not have inline variables
probinson marked an inline comment as done. Comment at: lib/Sema/SemaDecl.cpp:6189-6191 @@ -6188,2 +6188,5 @@ << FixItHint::CreateRemoval(D.getDeclSpec().getInlineSpecLoc()); +} else if (!getLangOpts().CPlusPlus) { + Diag(D.getDeclSpec().getInlineSpecLoc(), diag::err_inline_non_function) + << 0; } else { majnemer wrote: > I'd suggest sorting this condition higher. It doesn't make much sense to > mention block scopes when inline variables are prohibited in all contexts in > C. Right... for some reason the word 'block' in the comment made me think it was an Objective-C thing. The C-language check is first now. https://reviews.llvm.org/D22113 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D22113: C does not have inline variables
majnemer added a subscriber: majnemer. Comment at: lib/Sema/SemaDecl.cpp:6189-6191 @@ -6188,2 +6188,5 @@ << FixItHint::CreateRemoval(D.getDeclSpec().getInlineSpecLoc()); +} else if (!getLangOpts().CPlusPlus) { + Diag(D.getDeclSpec().getInlineSpecLoc(), diag::err_inline_non_function) + << 0; } else { I'd suggest sorting this condition higher. It doesn't make much sense to mention block scopes when inline variables are prohibited in all contexts in C. https://reviews.llvm.org/D22113 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D22113: C does not have inline variables
aaron.ballman added a subscriber: aaron.ballman. aaron.ballman accepted this revision. aaron.ballman added a reviewer: aaron.ballman. aaron.ballman added a comment. This revision is now accepted and ready to land. LGTM! I don't think we intended this to be an extension for C. https://reviews.llvm.org/D22113 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D22113: C does not have inline variables
probinson added a comment. Ping. https://reviews.llvm.org/D22113 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D22113: C does not have inline variables
probinson created this revision. probinson added a reviewer: rsmith. probinson added a subscriber: cfe-commits. We have a C test that now gets a warning about a C++1z extension, which seems inappropriate. http://reviews.llvm.org/D22113 Files: lib/Sema/SemaDecl.cpp test/Sema/inline.c Index: test/Sema/inline.c === --- test/Sema/inline.c +++ 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: lib/Sema/SemaDecl.cpp === --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -6186,6 +6186,9 @@ Diag(D.getDeclSpec().getInlineSpecLoc(), diag::err_inline_declaration_block_scope) << Name << FixItHint::CreateRemoval(D.getDeclSpec().getInlineSpecLoc()); +} else if (!getLangOpts().CPlusPlus) { + Diag(D.getDeclSpec().getInlineSpecLoc(), diag::err_inline_non_function) + << 0; } else { Diag(D.getDeclSpec().getInlineSpecLoc(), getLangOpts().CPlusPlus1z ? diag::warn_cxx14_compat_inline_variable Index: test/Sema/inline.c === --- test/Sema/inline.c +++ 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: lib/Sema/SemaDecl.cpp === --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -6186,6 +6186,9 @@ Diag(D.getDeclSpec().getInlineSpecLoc(), diag::err_inline_declaration_block_scope) << Name << FixItHint::CreateRemoval(D.getDeclSpec().getInlineSpecLoc()); +} else if (!getLangOpts().CPlusPlus) { + Diag(D.getDeclSpec().getInlineSpecLoc(), diag::err_inline_non_function) + << 0; } else { Diag(D.getDeclSpec().getInlineSpecLoc(), getLangOpts().CPlusPlus1z ? diag::warn_cxx14_compat_inline_variable ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits