Commit c8a71589 by Paolo Carlini Committed by Paolo Carlini

decl.c (maybe_deduce_size_from_array_init): Use DECL_SOURCE_LOCATION in error_at.

/cp
2016-06-08  Paolo Carlini  <paolo.carlini@oracle.com>

	* decl.c (maybe_deduce_size_from_array_init): Use
	DECL_SOURCE_LOCATION in error_at.
	(layout_var_decl): Likewise.
	(check_array_initializer): Likewise.
	(check_initializer): Likewise.
	(duplicate_decls, check_elaborated_type_specifier): Tidy.

/testsuite
2016-06-08  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/init/array42.C: New.
	* g++.dg/init/array43.C: Likewise.
	* g++.dg/init/array44.C: Likewise.
	* g++.dg/init/array45.C: Likewise.
	* g++.dg/cpp0x/constexpr-ice10.C: Test column number too.
	* g++.dg/cpp0x/constexpr-incomplete1.C: Likewise.
	* g++.dg/cpp1y/auto-fn27.C: Likewise.
	* g++.dg/gomp/pr35751.C: Likewise.
	* g++.dg/init/array23.C: Likewise.
	* g++.dg/init/brace2.C: Likewise.
	* g++.dg/init/brace6.C: Likewise.

From-SVN: r237240
parent 44a845ca
2016-06-08 Paolo Carlini <paolo.carlini@oracle.com>
* decl.c (maybe_deduce_size_from_array_init): Use
DECL_SOURCE_LOCATION in error_at.
(layout_var_decl): Likewise.
(check_array_initializer): Likewise.
(check_initializer): Likewise.
(duplicate_decls, check_elaborated_type_specifier): Tidy.
2016-06-08 Martin Sebor <msebor@redhat.com> 2016-06-08 Martin Sebor <msebor@redhat.com>
Jakub Jelinek <jakub@redhat.com> Jakub Jelinek <jakub@redhat.com>
......
...@@ -1393,7 +1393,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend) ...@@ -1393,7 +1393,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
{ {
if (DECL_INITIAL (olddecl)) if (DECL_INITIAL (olddecl))
inform (DECL_SOURCE_LOCATION (olddecl), inform (DECL_SOURCE_LOCATION (olddecl),
"previous definition of %q+D was here", olddecl); "previous definition of %qD was here", olddecl);
else else
inform (DECL_SOURCE_LOCATION (olddecl), inform (DECL_SOURCE_LOCATION (olddecl),
"previous declaration of %qD was here", olddecl); "previous declaration of %qD was here", olddecl);
...@@ -5266,13 +5266,16 @@ maybe_deduce_size_from_array_init (tree decl, tree init) ...@@ -5266,13 +5266,16 @@ maybe_deduce_size_from_array_init (tree decl, tree init)
do_default); do_default);
if (failure == 1) if (failure == 1)
{ {
error ("initializer fails to determine size of %qD", decl); error_at (EXPR_LOC_OR_LOC (initializer,
DECL_SOURCE_LOCATION (decl)),
"initializer fails to determine size of %qD", decl);
} }
else if (failure == 2) else if (failure == 2)
{ {
if (do_default) if (do_default)
{ {
error ("array size missing in %qD", decl); error_at (DECL_SOURCE_LOCATION (decl),
"array size missing in %qD", decl);
} }
/* If a `static' var's size isn't known, make it extern as /* If a `static' var's size isn't known, make it extern as
well as static, so it does not get allocated. If it's not well as static, so it does not get allocated. If it's not
...@@ -5283,7 +5286,8 @@ maybe_deduce_size_from_array_init (tree decl, tree init) ...@@ -5283,7 +5286,8 @@ maybe_deduce_size_from_array_init (tree decl, tree init)
} }
else if (failure == 3) else if (failure == 3)
{ {
error ("zero-size array %qD", decl); error_at (DECL_SOURCE_LOCATION (decl),
"zero-size array %qD", decl);
} }
} }
...@@ -5322,7 +5326,8 @@ layout_var_decl (tree decl) ...@@ -5322,7 +5326,8 @@ layout_var_decl (tree decl)
/* An automatic variable with an incomplete type: that is an error. /* An automatic variable with an incomplete type: that is an error.
Don't talk about array types here, since we took care of that Don't talk about array types here, since we took care of that
message in grokdeclarator. */ message in grokdeclarator. */
error ("storage size of %qD isn%'t known", decl); error_at (DECL_SOURCE_LOCATION (decl),
"storage size of %qD isn%'t known", decl);
TREE_TYPE (decl) = error_mark_node; TREE_TYPE (decl) = error_mark_node;
} }
#if 0 #if 0
...@@ -5345,7 +5350,8 @@ layout_var_decl (tree decl) ...@@ -5345,7 +5350,8 @@ layout_var_decl (tree decl)
constant_expression_warning (DECL_SIZE (decl)); constant_expression_warning (DECL_SIZE (decl));
else else
{ {
error ("storage size of %qD isn%'t constant", decl); error_at (DECL_SOURCE_LOCATION (decl),
"storage size of %qD isn%'t constant", decl);
TREE_TYPE (decl) = error_mark_node; TREE_TYPE (decl) = error_mark_node;
} }
} }
...@@ -5954,7 +5960,8 @@ check_array_initializer (tree decl, tree type, tree init) ...@@ -5954,7 +5960,8 @@ check_array_initializer (tree decl, tree type, tree init)
if (!COMPLETE_TYPE_P (complete_type (element_type))) if (!COMPLETE_TYPE_P (complete_type (element_type)))
{ {
if (decl) if (decl)
error ("elements of array %q#D have incomplete type", decl); error_at (DECL_SOURCE_LOCATION (decl),
"elements of array %q#D have incomplete type", decl);
else else
error ("elements of array %q#T have incomplete type", type); error ("elements of array %q#T have incomplete type", type);
return true; return true;
...@@ -6018,7 +6025,8 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups) ...@@ -6018,7 +6025,8 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
} }
else if (!COMPLETE_TYPE_P (type)) else if (!COMPLETE_TYPE_P (type))
{ {
error ("%q#D has incomplete type", decl); error_at (DECL_SOURCE_LOCATION (decl),
"%q#D has incomplete type", decl);
TREE_TYPE (decl) = error_mark_node; TREE_TYPE (decl) = error_mark_node;
return NULL_TREE; return NULL_TREE;
} }
...@@ -6038,8 +6046,9 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups) ...@@ -6038,8 +6046,9 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
} }
else if (init_len != 1 && TREE_CODE (type) != COMPLEX_TYPE) else if (init_len != 1 && TREE_CODE (type) != COMPLEX_TYPE)
{ {
error ("scalar object %qD requires one element in initializer", error_at (EXPR_LOC_OR_LOC (init, DECL_SOURCE_LOCATION (decl)),
decl); "scalar object %qD requires one element in "
"initializer", decl);
TREE_TYPE (decl) = error_mark_node; TREE_TYPE (decl) = error_mark_node;
return NULL_TREE; return NULL_TREE;
} }
...@@ -6081,9 +6090,10 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups) ...@@ -6081,9 +6090,10 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
{ {
/* Don't reshape if the class has constructors. */ /* Don't reshape if the class has constructors. */
if (cxx_dialect == cxx98) if (cxx_dialect == cxx98)
error ("in C++98 %qD must be initialized by constructor, " error_at (EXPR_LOC_OR_LOC (init, DECL_SOURCE_LOCATION (decl)),
"not by %<{...}%>", "in C++98 %qD must be initialized by "
decl); "constructor, not by %<{...}%>",
decl);
} }
else if (VECTOR_TYPE_P (type) && TYPE_VECTOR_OPAQUE (type)) else if (VECTOR_TYPE_P (type) && TYPE_VECTOR_OPAQUE (type))
{ {
...@@ -6175,8 +6185,11 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups) ...@@ -6175,8 +6185,11 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
&& DECL_INITIAL (decl) && DECL_INITIAL (decl)
&& TREE_CODE (DECL_INITIAL (decl)) == STRING_CST && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
&& PAREN_STRING_LITERAL_P (DECL_INITIAL (decl))) && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
warning (0, "array %qD initialized by parenthesized string literal %qE", warning_at (EXPR_LOC_OR_LOC (DECL_INITIAL (decl),
decl, DECL_INITIAL (decl)); DECL_SOURCE_LOCATION (decl)),
0, "array %qD initialized by parenthesized "
"string literal %qE",
decl, DECL_INITIAL (decl));
init = NULL; init = NULL;
} }
} }
...@@ -12528,14 +12541,14 @@ check_elaborated_type_specifier (enum tag_types tag_code, ...@@ -12528,14 +12541,14 @@ check_elaborated_type_specifier (enum tag_types tag_code,
&& tag_code != typename_type) && tag_code != typename_type)
{ {
error ("%qT referred to as %qs", type, tag_name (tag_code)); error ("%qT referred to as %qs", type, tag_name (tag_code));
inform (input_location, "%q+T has a previous declaration here", type); inform (location_of (type), "%qT has a previous declaration here", type);
return error_mark_node; return error_mark_node;
} }
else if (TREE_CODE (type) != ENUMERAL_TYPE else if (TREE_CODE (type) != ENUMERAL_TYPE
&& tag_code == enum_type) && tag_code == enum_type)
{ {
error ("%qT referred to as enum", type); error ("%qT referred to as enum", type);
inform (input_location, "%q+T has a previous declaration here", type); inform (location_of (type), "%qT has a previous declaration here", type);
return error_mark_node; return error_mark_node;
} }
else if (!allow_template_p else if (!allow_template_p
......
2016-06-08 Paolo Carlini <paolo.carlini@oracle.com>
* g++.dg/init/array42.C: New.
* g++.dg/init/array43.C: Likewise.
* g++.dg/init/array44.C: Likewise.
* g++.dg/init/array45.C: Likewise.
* g++.dg/cpp0x/constexpr-ice10.C: Test column number too.
* g++.dg/cpp0x/constexpr-incomplete1.C: Likewise.
* g++.dg/cpp1y/auto-fn27.C: Likewise.
* g++.dg/gomp/pr35751.C: Likewise.
* g++.dg/init/array23.C: Likewise.
* g++.dg/init/brace2.C: Likewise.
* g++.dg/init/brace6.C: Likewise.
2016-06-08 Martin Sebor <msebor@redhat.com> 2016-06-08 Martin Sebor <msebor@redhat.com>
Jakub Jelinek <jakub@redhat.com> Jakub Jelinek <jakub@redhat.com>
......
...@@ -4,5 +4,5 @@ ...@@ -4,5 +4,5 @@
struct A struct A
{ {
constexpr A() {} constexpr A() {}
static constexpr A a[2] = {}; // { dg-error "incomplete" } static constexpr A a[2] = {}; // { dg-error "22:elements of array 'constexpr const A A::a \\\[2\\\]' have incomplete type" }
}; };
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
struct A struct A
{ {
static constexpr A a = 1; // { dg-error "incomplete" } static constexpr A a = 1; // { dg-error "22:'constexpr const A A::a' has incomplete type" }
constexpr A(int i) { } constexpr A(int i) { }
}; };
...@@ -31,7 +31,7 @@ F<T>::bar (const G &) ...@@ -31,7 +31,7 @@ F<T>::bar (const G &)
{ {
auto s = I; auto s = I;
typedef decltype (s) L; typedef decltype (s) L;
auto u =[&](L) { auto t = foo (J::K (), 0); }; // { dg-error "" } auto u =[&](L) { auto t = foo (J::K (), 0); }; // { dg-error "25:'void t' has incomplete type" }
} }
struct B { struct B {
typedef int G; typedef int G;
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
void void
foo (int i) foo (int i)
{ {
extern int a[i]; // { dg-error "storage size of" } extern int a[i]; // { dg-error "14:storage size of" }
static int b[i]; // { dg-error "storage size of" } static int b[i]; // { dg-error "14:storage size of" }
#pragma omp parallel #pragma omp parallel
{ {
......
...@@ -3,4 +3,4 @@ ...@@ -3,4 +3,4 @@
// array // array
struct A {A();int A::* t;}; struct A {A();int A::* t;};
A x[]; // { dg-error "size" } A x[]; // { dg-error "3:array size missing" }
char a[] = ("abc"); // { dg-warning "6:array 'a' initialized by parenthesized string literal" }
int a[] = 0; // { dg-error "5:initializer fails to determine size" }
// { dg-error "11:array must be initialized" "" { target *-*-* } 1 }
int a[] = { }; // { dg-error "5:zero-size array" }
int a[]; // { dg-error "5:storage size" }
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
int x = { 2 }; int x = { 2 };
const char * y = { "hello" }; const char * y = { "hello" };
int a = 2; int a = 2;
int b = { 2,3 }; // { dg-error "requires one element in initializer" } int b = { 2,3 }; // { dg-error "5:scalar object 'b' requires one element in initializer" }
int c = { { 2 } } ; // { dg-error "braces around scalar initializer" } int c = { { 2 } } ; // { dg-error "braces around scalar initializer" }
int d = {}; // { dg-error "initializer" "" { target { ! c++11 } } } int d = {}; // { dg-error "initializer" "" { target { ! c++11 } } }
...@@ -17,8 +17,8 @@ struct D { int c; }; ...@@ -17,8 +17,8 @@ struct D { int c; };
int main() int main()
{ {
int i = { 1 }; int i = { 1 };
int j = { 1, 2 }; /* { dg-error "requires one element" } */ int j = { 1, 2 }; /* { dg-error "8:scalar object 'j' requires one element" } */
A a = { 6 }; /* { dg-error "initialize" "" { target { ! c++11 } } } */ A a = { 6 }; /* { dg-error "6:in C\\+\\+98 'a' must be initialized" "" { target { ! c++11 } } } */
B b = { 6 }; /* { dg-error "" } */ B b = { 6 }; /* { dg-error "" } */
C c = { 6 }; /* { dg-error "too many initializers" } */ C c = { 6 }; /* { dg-error "too many initializers" } */
D d = { 6 }; D d = { 6 };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment