alignof(int[]) (was Re: [C++ Patch] PR 51316)
On 12/28/2011 07:07 PM, Paolo Carlini wrote: I think the resolution of core/930 and C++11 itself are pretty clear: alignof of an array of unknown bound is fine, provided the element type is complete of course. I think it makes sense for this change to apply to C as well, on the same principle that an array of unknown bound does have known alignment. C maintainers? Jason
Re: alignof(int[]) (was Re: [C++ Patch] PR 51316)
Hi, On 12/30/2011 06:27 PM, Jason Merrill wrote: On 12/28/2011 07:07 PM, Paolo Carlini wrote: I think the resolution of core/930 and C++11 itself are pretty clear: alignof of an array of unknown bound is fine, provided the element type is complete of course. I think it makes sense for this change to apply to C as well, on the same principle that an array of unknown bound does have known alignment. C maintainers? FWIW, I also think it would make sense but - I'm not sure whether you went through the audit trail - Joseph maintained in Comment #3 that C1X is pretty clear about a required diagnostics. Paolo.
Re: alignof(int[]) (was Re: [C++ Patch] PR 51316)
On Fri, 30 Dec 2011, Jason Merrill wrote: On 12/28/2011 07:07 PM, Paolo Carlini wrote: I think the resolution of core/930 and C++11 itself are pretty clear: alignof of an array of unknown bound is fine, provided the element type is complete of course. I think it makes sense for this change to apply to C as well, on the same principle that an array of unknown bound does have known alignment. C maintainers? In the absence of a resolution of a DR against C11 that allows alignof in this case, I think we should continue to disallow it for C. -- Joseph S. Myers jos...@codesourcery.com
Re: alignof(int[]) (was Re: [C++ Patch] PR 51316)
On 12/30/2011 12:38 PM, Joseph S. Myers wrote: In the absence of a resolution of a DR against C11 that allows alignof in this case, I think we should continue to disallow it for C. Ah, I didn't realize that C11 had alignof as well. OK, then. Jason
[C++ Patch] PR 51316
Hi, I think the resolution of core/930 and C++11 itself are pretty clear: alignof of an array of unknown bound is fine, provided the element type is complete of course. Tested x86_64-linux. Thanks, Paolo. // /c-family 2011-12-29 Paolo Carlini paolo.carl...@oracle.com 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-29 Paolo Carlini paolo.carl...@oracle.com PR c++/51316 * g++.dg/cpp0x/alignof4.C: New. Index: testsuite/g++.dg/cpp0x/alignof4.C === --- testsuite/g++.dg/cpp0x/alignof4.C (revision 0) +++ testsuite/g++.dg/cpp0x/alignof4.C (revision 0) @@ -0,0 +1,7 @@ +// PR c++/51316 +// { dg-options -std=c++0x } + +int main() +{ + alignof(int []); +} Index: c-family/c-common.c === --- c-family/c-common.c (revision 182710) +++ c-family/c-common.c (working copy) @@ -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)