public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101232] New: Bad error message with stray semicolon in initializer
@ 2021-06-27 9:50 tobi at gcc dot gnu.org
2021-07-08 1:52 ` [Bug c++/101232] " tobi at gcc dot gnu.org
2021-07-14 1:47 ` tobi at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: tobi at gcc dot gnu.org @ 2021-06-27 9:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101232
Bug ID: 101232
Summary: Bad error message with stray semicolon in initializer
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: tobi at gcc dot gnu.org
Target Milestone: ---
This example (Link to compiler explorer: -> https://godbolt.org/z/rxsreYs8Y
<-):
=========================
struct X {
int a;
int b;
};
void f() {
auto x = X{ 1, 2; };
}
========================
Gives the fairly misleading error message
<source>: In function 'void f()':
<source>:7:15: error: expected primary-expression before '{' token
7 | auto x = X{ 1, 2; };
| ^
The error message is of the same kind all the way from GCC 4.1.2 up to the
current trunk.
For comparison, clang gives the much more helpful
<source>:7:21: error: unexpected ';' before '}'
auto x = X{ 1, 2; };
^
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/101232] Bad error message with stray semicolon in initializer
2021-06-27 9:50 [Bug c++/101232] New: Bad error message with stray semicolon in initializer tobi at gcc dot gnu.org
@ 2021-07-08 1:52 ` tobi at gcc dot gnu.org
2021-07-14 1:47 ` tobi at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: tobi at gcc dot gnu.org @ 2021-07-08 1:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101232
--- Comment #1 from Tobias Schlüter <tobi at gcc dot gnu.org> ---
BTW an equivalent C example gives the proper error both with C and C++
https://godbolt.org/z/sWc67eWT8
=====================
struct X {
int a;
int b;
};
void f() {
struct X x = { 1, 2; };
}
=====================
<source>: In function 'void f()':
<source>:7:24: error: expected '}' before ';' token
7 | struct X x = { 1, 2; };
| ~ ^
<source>: At global scope:
<source>:8:1: error: expected declaration before '}' token
8 | }
| ^
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/101232] Bad error message with stray semicolon in initializer
2021-06-27 9:50 [Bug c++/101232] New: Bad error message with stray semicolon in initializer tobi at gcc dot gnu.org
2021-07-08 1:52 ` [Bug c++/101232] " tobi at gcc dot gnu.org
@ 2021-07-14 1:47 ` tobi at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: tobi at gcc dot gnu.org @ 2021-07-14 1:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101232
--- Comment #2 from Tobias Schlüter <tobi at gcc dot gnu.org> ---
Here's another way to trigger this, inspired by my other PR101435
(https://godbolt.org/z/no6aEqvh3):
===============================
template<typename U, int dim>
class X {
public:
U v;
using Scalar = U;
static constexpr auto Dim = dim;
explicit X(U x) : v(x) {}
template<typename T>
X<T, dim> cast()
{
return X<T, dim>(T{v});
}
};
void f(int err) {
auto propertyHelper = [err]<typename M>(M&& fallback) -> M {
using FloatM = X<float, M::Dim>;
FloatM v{0};
return err == 0 ? M{ v.template cast<typename M::Scalar>(); } :
fallback;
};
}
=======================
Which gives a comically wrong cascade of errors:
---------------------------
<source>: In lambda function:
<source>:23:28: error: expected primary-expression before '{' token
23 | return err == 0 ? M{ v.template cast<typename M::Scalar>(); } :
fallback;
| ^
<source>:23:28: error: expected ':' before '{' token
23 | return err == 0 ? M{ v.template cast<typename M::Scalar>(); } :
fallback;
| ^
| :
<source>:23:28: error: expected primary-expression before '{' token
<source>:23:28: error: expected ';' before '{' token
23 | return err == 0 ? M{ v.template cast<typename M::Scalar>(); } :
fallback;
| ^
| ;
<source>:23:71: error: expected primary-expression before ':' token
23 | return err == 0 ? M{ v.template cast<typename M::Scalar>(); } :
fallback;
| ^
Compiler returned: 1
---------------------------------
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-07-14 1:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-27 9:50 [Bug c++/101232] New: Bad error message with stray semicolon in initializer tobi at gcc dot gnu.org
2021-07-08 1:52 ` [Bug c++/101232] " tobi at gcc dot gnu.org
2021-07-14 1:47 ` tobi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).