r173789 - Produce a diagnostic if alignas is applied to an expression. Neither C11 nor
Richard Smith
richard-llvm at metafoo.co.uk
Tue Jan 29 02:18:18 PST 2013
Author: rsmith
Date: Tue Jan 29 04:18:18 2013
New Revision: 173789
URL: http://llvm.org/viewvc/llvm-project?rev=173789&view=rev
Log:
Produce a diagnostic if alignas is applied to an expression. Neither C11 nor
C++11 allows that.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/test/SemaCXX/alignof-sizeof-reference.cpp
cfe/trunk/test/SemaCXX/attr-cxx0x.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=173789&r1=173788&r2=173789&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Tue Jan 29 04:18:18 2013
@@ -95,6 +95,8 @@ def warn_cxx98_compat_enum_fixed_underly
def warn_cxx98_compat_alignof : Warning<
"alignof expressions are incompatible with C++98">,
InGroup<CXX98Compat>, DefaultIgnore;
+def ext_alignof_expr : ExtWarn<
+ "%0 applied to an expression is a GNU extension">, InGroup<GNU>;
def warn_microsoft_dependent_exists : Warning<
"dependent %select{__if_not_exists|__if_exists}0 declarations are ignored">,
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=173789&r1=173788&r2=173789&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Tue Jan 29 04:18:18 2013
@@ -1609,11 +1609,11 @@ Parser::ParseExprAfterUnaryExprOrTypeTra
/// unary-expression: [C99 6.5.3]
/// 'sizeof' unary-expression
/// 'sizeof' '(' type-name ')'
-/// [C++0x] 'sizeof' '...' '(' identifier ')'
+/// [C++11] 'sizeof' '...' '(' identifier ')'
/// [GNU] '__alignof' unary-expression
/// [GNU] '__alignof' '(' type-name ')'
/// [C11] '_Alignof' '(' type-name ')'
-/// [C++0x] 'alignof' '(' type-id ')'
+/// [C++11] 'alignof' '(' type-id ')'
/// \endverbatim
ExprResult Parser::ParseUnaryExprOrTypeTraitExpression() {
assert((Tok.is(tok::kw_sizeof) || Tok.is(tok::kw___alignof) ||
@@ -1623,7 +1623,7 @@ ExprResult Parser::ParseUnaryExprOrTypeT
Token OpTok = Tok;
ConsumeToken();
- // [C++0x] 'sizeof' '...' '(' identifier ')'
+ // [C++11] 'sizeof' '...' '(' identifier ')'
if (Tok.is(tok::ellipsis) && OpTok.is(tok::kw_sizeof)) {
SourceLocation EllipsisLoc = ConsumeToken();
SourceLocation LParenLoc, RParenLoc;
@@ -1694,6 +1694,9 @@ ExprResult Parser::ParseUnaryExprOrTypeT
CastTy.getAsOpaquePtr(),
CastRange);
+ if (OpTok.is(tok::kw_alignof) || OpTok.is(tok::kw__Alignof))
+ Diag(OpTok, diag::ext_alignof_expr) << OpTok.getIdentifierInfo();
+
// If we get here, the operand to the sizeof/alignof was an expresion.
if (!Operand.isInvalid())
Operand = Actions.ActOnUnaryExprOrTypeTraitExpr(OpTok.getLocation(),
Modified: cfe/trunk/test/SemaCXX/alignof-sizeof-reference.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/alignof-sizeof-reference.cpp?rev=173789&r1=173788&r2=173789&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/alignof-sizeof-reference.cpp (original)
+++ cfe/trunk/test/SemaCXX/alignof-sizeof-reference.cpp Tue Jan 29 04:18:18 2013
@@ -4,8 +4,10 @@ struct s0; // expected-note {{forward de
char ar[sizeof(s0&)]; // expected-error {{invalid application of 'sizeof' to an incomplete type}}
void test() {
char &r = ar[0];
- static_assert(alignof(r) == 1, "bad alignment");
+ static_assert(alignof(r) == 1, "bad alignment"); // expected-warning {{GNU extension}}
+ static_assert(alignof(char&) == 1, "bad alignment");
static_assert(sizeof(r) == 1, "bad size");
+ static_assert(sizeof(char&) == 1, "bad size");
}
void f(); // expected-note{{possible target for call}}
@@ -18,5 +20,5 @@ void g() {
template<typename T> void f_template(); // expected-note{{possible target for call}}
template<typename T> void f_template(T*); // expected-note{{possible target for call}}
void rdar9659191() {
- (void)alignof(f_template<int>); // expected-error{{reference to overloaded function could not be resolved; did you mean to call it?}}
+ (void)alignof(f_template<int>); // expected-error{{reference to overloaded function could not be resolved; did you mean to call it?}} expected-warning {{GNU extension}}
}
Modified: cfe/trunk/test/SemaCXX/attr-cxx0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-cxx0x.cpp?rev=173789&r1=173788&r2=173789&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-cxx0x.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-cxx0x.cpp Tue Jan 29 04:18:18 2013
@@ -28,9 +28,9 @@ template <unsigned... A> alignas(A...) s
typedef char align_typedef alignas(8); // expected-error {{'alignas' attribute only applies to variables, functions and tag types}}
template<typename T> using align_alias_template = align_typedef alignas(8); // expected-error {{'alignas' attribute cannot be applied to types}}
-static_assert(alignof(align_big) == alignof(int), "k's alignment is wrong");
-static_assert(alignof(align_small) == 1, "j's alignment is wrong");
-static_assert(alignof(align_multiple) == 8, "l's alignment is wrong");
+static_assert(alignof(align_big) == alignof(int), "k's alignment is wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}}
+static_assert(alignof(align_small) == 1, "j's alignment is wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}}
+static_assert(alignof(align_multiple) == 8, "l's alignment is wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}}
static_assert(alignof(align_member) == 8, "quuux's alignment is wrong");
static_assert(sizeof(align_member) == 8, "quuux's size is wrong");
static_assert(alignof(align_class_template<8>) == 8, "template's alignment is wrong");
More information about the cfe-commits
mailing list