diff options
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 13 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 11 | ||||
-rw-r--r-- | test/Sema/exprs.c | 2 | ||||
-rw-r--r-- | test/SemaCXX/attr-cxx0x.cpp | 4 |
4 files changed, 17 insertions, 13 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index d23df6cb3b..e08c5fc985 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -3940,16 +3940,17 @@ def err_atomic_specifier_bad_type : Error< "%1 %select{||||||which is not trivially copyable}0">; // Expressions. -def ext_sizeof_function_type : Extension< - "invalid application of 'sizeof' to a function type">, InGroup<PointerArith>; -def ext_sizeof_void_type : Extension< - "invalid application of '%select{sizeof|__alignof|vec_step}0' to a void " +def ext_sizeof_alignof_function_type : Extension< + "invalid application of '%select{sizeof|alignof|vec_step}0' to a " + "function type">, InGroup<PointerArith>; +def ext_sizeof_alignof_void_type : Extension< + "invalid application of '%select{sizeof|alignof|vec_step}0' to a void " "type">, InGroup<PointerArith>; def err_sizeof_alignof_incomplete_type : Error< - "invalid application of '%select{sizeof|__alignof|vec_step}0' to an " + "invalid application of '%select{sizeof|alignof|vec_step}0' to an " "incomplete type %1">; def err_sizeof_alignof_bitfield : Error< - "invalid application of '%select{sizeof|__alignof}0' to bit-field">; + "invalid application of '%select{sizeof|alignof}0' to bit-field">; def err_vecstep_non_scalar_vector_type : Error< "'vec_step' requires built-in scalar or vector type, %0 invalid">; def err_offsetof_incomplete_type : Error< diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index f52621a80b..bf4632c7bf 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -3012,16 +3012,17 @@ static bool CheckExtensionTraitOperandType(Sema &S, QualType T, SourceRange ArgRange, UnaryExprOrTypeTrait TraitKind) { // C99 6.5.3.4p1: - if (T->isFunctionType()) { - // alignof(function) is allowed as an extension. - if (TraitKind == UETT_SizeOf) - S.Diag(Loc, diag::ext_sizeof_function_type) << ArgRange; + if (T->isFunctionType() && + (TraitKind == UETT_SizeOf || TraitKind == UETT_AlignOf)) { + // sizeof(function)/alignof(function) is allowed as an extension. + S.Diag(Loc, diag::ext_sizeof_alignof_function_type) + << TraitKind << ArgRange; return false; } // Allow sizeof(void)/alignof(void) as an extension. if (T->isVoidType()) { - S.Diag(Loc, diag::ext_sizeof_void_type) << TraitKind << ArgRange; + S.Diag(Loc, diag::ext_sizeof_alignof_void_type) << TraitKind << ArgRange; return false; } diff --git a/test/Sema/exprs.c b/test/Sema/exprs.c index df3e25857c..2fb17e4880 100644 --- a/test/Sema/exprs.c +++ b/test/Sema/exprs.c @@ -94,7 +94,7 @@ int test8(void) { struct f { int x : 4; float y[]; }; int test9(struct f *P) { int R; - R = __alignof(P->x); // expected-error {{invalid application of '__alignof' to bit-field}} + R = __alignof(P->x); // expected-error {{invalid application of 'alignof' to bit-field}} R = __alignof(P->y); // ok. R = sizeof(P->x); // expected-error {{invalid application of 'sizeof' to bit-field}} return R; diff --git a/test/SemaCXX/attr-cxx0x.cpp b/test/SemaCXX/attr-cxx0x.cpp index 002800e749..e9276cd2d9 100644 --- a/test/SemaCXX/attr-cxx0x.cpp +++ b/test/SemaCXX/attr-cxx0x.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++11 %s +// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -pedantic -std=c++11 %s int align_illegal alignas(3); //expected-error {{requested alignment is not a power of 2}} char align_big alignas(int); @@ -43,3 +43,5 @@ static_assert(alignof(align_class_template<16>) == 16, "template's alignment is static_assert(alignof(align_class_temp_pack_type<short, int, long>) == alignof(long), "template's alignment is wrong"); static_assert(alignof(align_class_temp_pack_expr<8, 16, 32>) == 32, "template's alignment is wrong"); static_assert(alignof(outer<int,char>::inner<double,short>) == alignof(int) * alignof(double), "template's alignment is wrong"); + +static_assert(alignof(int(int)) >= 1, "alignof(function) not positive"); // expected-warning{{invalid application of 'alignof' to a function type}} |