From: Paolo Carlini Date: Thu, 6 Dec 2018 08:23:04 +0000 (+0000) Subject: decl2.c (grokbitfield): Use DECL_SOURCE_LOCATION in error message... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=34b1a7d63d96b0c39734c0b6dfee76715506efcf;p=gcc.git decl2.c (grokbitfield): Use DECL_SOURCE_LOCATION in error message... /cp 2018-12-06 Paolo Carlini * decl2.c (grokbitfield): Use DECL_SOURCE_LOCATION in error message; print the type too; fix thinko in INDIRECT_TYPE_P use. /testsuite 2018-12-06 Paolo Carlini * g++.dg/parse/bitfield6b.C: New. * g++.dg/parse/bitfield3.C: Test location and type. From-SVN: r266841 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3958992a57a..704e01defcf 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-12-06 Paolo Carlini + + * decl2.c (grokbitfield): Use DECL_SOURCE_LOCATION in error message; + print the type too; fix thinko in INDIRECT_TYPE_P use. + 2018-12-05 Alexandre Oliva PR c++/85569 diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index ffc0d0d6ec4..79abdaebe86 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1016,18 +1016,21 @@ grokbitfield (const cp_declarator *declarator, if (value == error_mark_node) return NULL_TREE; /* friends went bad. */ - if (TREE_TYPE (value) == error_mark_node) + + tree type = TREE_TYPE (value); + if (type == error_mark_node) return value; /* Pass friendly classes back. */ if (VOID_TYPE_P (value)) return void_type_node; - if (!INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value)) - && (INDIRECT_TYPE_P (value) - || !dependent_type_p (TREE_TYPE (value)))) + if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type) + && (INDIRECT_TYPE_P (type) || !dependent_type_p (type))) { - error ("bit-field %qD with non-integral type", value); + error_at (DECL_SOURCE_LOCATION (value), + "bit-field %qD with non-integral type %qT", + value, type); return error_mark_node; } @@ -1048,7 +1051,7 @@ grokbitfield (const cp_declarator *declarator, return NULL_TREE; } - if (width && TYPE_WARN_IF_NOT_ALIGN (TREE_TYPE (value))) + if (width && TYPE_WARN_IF_NOT_ALIGN (type)) { error ("cannot declare bit-field %qD with % type", DECL_NAME (value)); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d330d0eaba6..922cc52a0a7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-12-06 Paolo Carlini + + * g++.dg/parse/bitfield6b.C: New. + * g++.dg/parse/bitfield3.C: Test location and type. + 2018-12-06 Iain Sandoe * lib/c-compat.exp (compat-use-alt-compiler): diff --git a/gcc/testsuite/g++.dg/parse/bitfield3.C b/gcc/testsuite/g++.dg/parse/bitfield3.C index 387548a6827..efff2ec993e 100644 --- a/gcc/testsuite/g++.dg/parse/bitfield3.C +++ b/gcc/testsuite/g++.dg/parse/bitfield3.C @@ -5,5 +5,5 @@ typedef void (func_type)(); struct A { - friend func_type f : 2; /* { dg-error "with non-integral type" } */ + friend func_type f : 2; /* { dg-error "20:bit-field .void f\\(\\). with non-integral type .func_type." } */ }; diff --git a/gcc/testsuite/g++.dg/parse/bitfield6b.C b/gcc/testsuite/g++.dg/parse/bitfield6b.C new file mode 100644 index 00000000000..1cd99a5996e --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/bitfield6b.C @@ -0,0 +1,4 @@ +typedef void a(); +struct A { +a a1: 1; // { dg-error "3:bit-field .void A::a1\\(\\). with non-integral type .void \\(A::\\)\\(\\)." } +};