diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2019-07-10 08:24:54 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2019-07-10 08:24:54 +0000 |
commit | a620ef15027baace38d591709474f1a9519ba657 (patch) | |
tree | 4edea152284b330cfbefd2b2ec4971c5c2adb0ce | |
parent | caa0705cb68fa63e5b2cce9d9fe3561f1ba23e58 (diff) | |
download | gcc-a620ef15027baace38d591709474f1a9519ba657.zip gcc-a620ef15027baace38d591709474f1a9519ba657.tar.gz gcc-a620ef15027baace38d591709474f1a9519ba657.tar.bz2 |
decl.c (get_type_quals, [...]): New.
/cp
2019-07-10 Paolo Carlini <paolo.carlini@oracle.com>
* decl.c (get_type_quals,
smallest_type_location (const cp_decl_specifier_seq*)): New.
(check_tag_decl): Use smallest_type_location in error_at about
multiple types in one declaration.
(grokdeclarator): Use locations[ds_complex] in error_at about
complex invalid; use locations[ds_storage_class] in error_at
about static cdtor; use id_loc in error_at about flexible
array member in union; use get_type_quals.
/testsuite
2019-07-10 Paolo Carlini <paolo.carlini@oracle.com>
* g++.dg/diagnostic/complex-invalid-1.C: New.
* g++.dg/diagnostic/static-cdtor-1.C: Likewise.
* g++.dg/cpp1z/has-unique-obj-representations2.C: Test location
too.
* g++.dg/other/anon-union3.C: Adjust expected location.
* g++.dg/parse/error8.C: Likewise.
From-SVN: r273323
-rw-r--r-- | gcc/cp/ChangeLog | 11 | ||||
-rw-r--r-- | gcc/cp/decl.c | 52 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations2.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/diagnostic/complex-invalid-1.C | 1 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/diagnostic/static-cdtor-1.C | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/other/anon-union3.C | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/parse/error8.C | 2 |
8 files changed, 68 insertions, 18 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7609b20..bc788c1 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,14 @@ +2019-07-10 Paolo Carlini <paolo.carlini@oracle.com> + + * decl.c (get_type_quals, + smallest_type_location (const cp_decl_specifier_seq*)): New. + (check_tag_decl): Use smallest_type_location in error_at about + multiple types in one declaration. + (grokdeclarator): Use locations[ds_complex] in error_at about + complex invalid; use locations[ds_storage_class] in error_at + about static cdtor; use id_loc in error_at about flexible + array member in union; use get_type_quals. + 2019-07-09 Martin Sebor <msebor@redhat.com> PR c++/61339 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index a178b22..dbcf681 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -100,6 +100,7 @@ static tree build_cp_library_fn (tree, enum tree_code, tree, int); static void store_parm_decls (tree); static void initialize_local_var (tree, tree); static void expand_static_init (tree, tree); +static location_t smallest_type_location (const cp_decl_specifier_seq*); /* The following symbols are subsumed in the cp_global_trees array, and listed here individually for documentation purposes. @@ -4802,6 +4803,24 @@ warn_misplaced_attr_for_class_type (location_t location, class_type, class_key_or_enum_as_string (class_type)); } +/* Returns the cv-qualifiers that apply to the type specified + by the DECLSPECS. */ + +static int +get_type_quals (const cp_decl_specifier_seq *declspecs) +{ + int type_quals = TYPE_UNQUALIFIED; + + if (decl_spec_seq_has_spec_p (declspecs, ds_const)) + type_quals |= TYPE_QUAL_CONST; + if (decl_spec_seq_has_spec_p (declspecs, ds_volatile)) + type_quals |= TYPE_QUAL_VOLATILE; + if (decl_spec_seq_has_spec_p (declspecs, ds_restrict)) + type_quals |= TYPE_QUAL_RESTRICT; + + return type_quals; +} + /* Make sure that a declaration with no declarator is well-formed, i.e. just declares a tagged type or anonymous union. @@ -4821,7 +4840,8 @@ check_tag_decl (cp_decl_specifier_seq *declspecs, bool error_p = false; if (declspecs->multiple_types_p) - error ("multiple types in one declaration"); + error_at (smallest_type_location (declspecs), + "multiple types in one declaration"); else if (declspecs->redefined_builtin_type) { if (!in_system_header_at (input_location)) @@ -10142,6 +10162,13 @@ smallest_type_location (int type_quals, const location_t* locations) return min_location (loc, locations[ds_type_spec]); } +static location_t +smallest_type_location (const cp_decl_specifier_seq *declspecs) +{ + int type_quals = get_type_quals (declspecs); + return smallest_type_location (type_quals, declspecs->locations); +} + /* Check that it's OK to declare a function with the indicated TYPE and TYPE_QUALS. SFK indicates the kind of special function (if any) that this function is. OPTYPE is the type given in a conversion @@ -10407,7 +10434,7 @@ grokdeclarator (const cp_declarator *declarator, a member function. */ cp_ref_qualifier rqual = REF_QUAL_NONE; /* cv-qualifiers that apply to the type specified by the DECLSPECS. */ - int type_quals = TYPE_UNQUALIFIED; + int type_quals = get_type_quals (declspecs); tree raises = NULL_TREE; int template_count = 0; tree returned_attrs = NULL_TREE; @@ -10454,13 +10481,6 @@ grokdeclarator (const cp_declarator *declarator, if (concept_p) constexpr_p = true; - if (decl_spec_seq_has_spec_p (declspecs, ds_const)) - type_quals |= TYPE_QUAL_CONST; - if (decl_spec_seq_has_spec_p (declspecs, ds_volatile)) - type_quals |= TYPE_QUAL_VOLATILE; - if (decl_spec_seq_has_spec_p (declspecs, ds_restrict)) - type_quals |= TYPE_QUAL_RESTRICT; - if (decl_context == FUNCDEF) funcdef_flag = true, decl_context = NORMAL; else if (decl_context == MEMFUNCDEF) @@ -10999,7 +11019,8 @@ grokdeclarator (const cp_declarator *declarator, if (decl_spec_seq_has_spec_p (declspecs, ds_complex)) { if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE) - error ("complex invalid for %qs", name); + error_at (declspecs->locations[ds_complex], + "complex invalid for %qs", name); /* If a modifier is specified, the resulting complex is the complex form of TYPE. E.g, "complex short" is "complex short int". */ else if (type == integer_type_node) @@ -11578,9 +11599,12 @@ grokdeclarator (const cp_declarator *declarator, virtual. A constructor may not be static. A constructor may not be declared with ref-qualifier. */ if (staticp == 2) - error ((flags == DTOR_FLAG) - ? G_("destructor cannot be static member function") - : G_("constructor cannot be static member function")); + error_at (declspecs->locations[ds_storage_class], + (flags == DTOR_FLAG) + ? G_("destructor cannot be static member " + "function") + : G_("constructor cannot be static member " + "function")); if (memfn_quals) { error ((flags == DTOR_FLAG) @@ -12438,7 +12462,7 @@ grokdeclarator (const cp_declarator *declarator, && (TREE_CODE (ctype) == UNION_TYPE || TREE_CODE (ctype) == QUAL_UNION_TYPE)) { - error ("flexible array member in union"); + error_at (id_loc, "flexible array member in union"); type = error_mark_node; } else diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c9fa127..430c508 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2019-07-10 Paolo Carlini <paolo.carlini@oracle.com> + + * g++.dg/diagnostic/complex-invalid-1.C: New. + * g++.dg/diagnostic/static-cdtor-1.C: Likewise. + * g++.dg/cpp1z/has-unique-obj-representations2.C: Test location + too. + * g++.dg/other/anon-union3.C: Adjust expected location. + * g++.dg/parse/error8.C: Likewise. + 2019-07-09 Jan Hubicka <hubicka@ucw.cz> * g++.dg/lto/alias-3_0.C: New file. diff --git a/gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations2.C b/gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations2.C index c4ae555..f1f3388 100644 --- a/gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations2.C +++ b/gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations2.C @@ -1,7 +1,7 @@ struct S; struct T { S t; }; // { dg-error "incomplete type" } struct U { int u[sizeof (S)]; }; // { dg-error "incomplete type" } -union V { char c; char d[]; }; // { dg-error "flexible array member in union" } +union V { char c; char d[]; }; // { dg-error "24:flexible array member in union" } bool a = __has_unique_object_representations (S); // { dg-error "incomplete type" } bool b = __has_unique_object_representations (T); bool c = __has_unique_object_representations (U); diff --git a/gcc/testsuite/g++.dg/diagnostic/complex-invalid-1.C b/gcc/testsuite/g++.dg/diagnostic/complex-invalid-1.C new file mode 100644 index 0000000..5a61765 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/complex-invalid-1.C @@ -0,0 +1 @@ +__complex__ bool b; // { dg-error "1:complex invalid" } diff --git a/gcc/testsuite/g++.dg/diagnostic/static-cdtor-1.C b/gcc/testsuite/g++.dg/diagnostic/static-cdtor-1.C new file mode 100644 index 0000000..ae3fd56 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/static-cdtor-1.C @@ -0,0 +1,5 @@ +struct S +{ + static S(); // { dg-error "3:constructor" } + static ~S(); // { dg-error "3:destructor" } +}; diff --git a/gcc/testsuite/g++.dg/other/anon-union3.C b/gcc/testsuite/g++.dg/other/anon-union3.C index ca59d02..6f2946b 100644 --- a/gcc/testsuite/g++.dg/other/anon-union3.C +++ b/gcc/testsuite/g++.dg/other/anon-union3.C @@ -3,9 +3,9 @@ class C { auto union // { dg-error "storage class" "" { target { ! c++11 } } } - { // { dg-error "auto" "" { target c++11 } .-1 } + { // { dg-error "auto|multiple types" "" { target c++11 } .-1 } int a; - }; // { dg-error "multiple types" "" { target c++11 } } + }; register union // { dg-error "storage class" } { int b; diff --git a/gcc/testsuite/g++.dg/parse/error8.C b/gcc/testsuite/g++.dg/parse/error8.C index 61e42e0..135f078 100644 --- a/gcc/testsuite/g++.dg/parse/error8.C +++ b/gcc/testsuite/g++.dg/parse/error8.C @@ -5,5 +5,5 @@ struct A { friend typename struct B; }; // { dg-error "28:expected nested-name-specifier before 'struct'" "expected" { target *-*-* } 4 } -// { dg-error "35:multiple types in one declaration" "multiple" { target *-*-* } 4 } +// { dg-error "19:multiple types in one declaration" "multiple" { target *-*-* } 4 } // { dg-error "12:friend declaration does not name a class or function" "friend decl" { target *-*-* } 4 } |