From 73ac190a5e191440d3536b14c0a9c4b7390f216a Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 30 Dec 2011 21:11:20 +0000 Subject: [PATCH] re PR c++/51316 (alignof doesn't work with arrays of unknown bound) /c-family 2011-12-30 Paolo Carlini PR c++/51316 * c-common.c (c_sizeof_or_alignof_type): In C++ allow for alignof of array types with an unknown bound. /testsuite 2011-12-30 Paolo Carlini PR c++/51316 * g++.dg/cpp0x/alignof4.C: New. From-SVN: r182746 --- gcc/c-family/ChangeLog | 6 ++++++ gcc/c-family/c-common.c | 13 +++++++++++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/alignof4.C | 7 +++++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/alignof4.C diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index b076e7602f3..7850829108a 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2011-12-30 Paolo Carlini + + PR c++/51316 + * c-common.c (c_sizeof_or_alignof_type): In C++ allow for alignof + of array types with an unknown bound. + 2011-12-20 Joseph Myers * c-common.c (flag_isoc99): Update comment to refer to C11. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 6f88760c947..013c71a6420 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -4382,13 +4382,22 @@ c_sizeof_or_alignof_type (location_t loc, return error_mark_node; value = size_one_node; } - else if (!COMPLETE_TYPE_P (type)) + else if (!COMPLETE_TYPE_P (type) + && (!c_dialect_cxx () || is_sizeof || type_code != ARRAY_TYPE)) { if (complain) - error_at (loc, "invalid application of %qs to incomplete type %qT ", + error_at (loc, "invalid application of %qs to incomplete type %qT", op_name, type); return error_mark_node; } + else if (c_dialect_cxx () && type_code == ARRAY_TYPE + && !COMPLETE_TYPE_P (TREE_TYPE (type))) + { + if (complain) + error_at (loc, "invalid application of %qs to array type %qT of " + "incomplete element type", op_name, type); + return error_mark_node; + } else { if (is_sizeof) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c49c10012c3..34662342a8f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-12-30 Paolo Carlini + + PR c++/51316 + * g++.dg/cpp0x/alignof4.C: New. + 2011-12-29 Michael Meissner PR testsuite/51702 diff --git a/gcc/testsuite/g++.dg/cpp0x/alignof4.C b/gcc/testsuite/g++.dg/cpp0x/alignof4.C new file mode 100644 index 00000000000..92d636faf09 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alignof4.C @@ -0,0 +1,7 @@ +// PR c++/51316 +// { dg-options "-std=c++0x" } + +int main() +{ + alignof(int []); +}