[Bug c++/85959] g++ doesn't show second error
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jan 6 22:31:10 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85959
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Last reconfirmed| |2022-01-06
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The carat was fixed in GCC 8:
<source>: In function 'int main()':
<source>:14:19: error: binding reference of type 'int&' to 'const int' discards
qualifiers
strstripspace(unused, two);
^~~~~~
<source>:4:6: note: initializing argument 1 of 'void strstripspace(int&,
int&)'
void strstripspace(int & value, int & two)
^~~~~~~~~~~~~
----- CUT ----
clang also only shows about the first argument:
<source>:14:5: error: no matching function for call to 'strstripspace'
strstripspace(unused, two);
^~~~~~~~~~~~~
<source>:4:6: note: candidate function not viable: 1st argument ('const int')
would lose const qualifier
void strstripspace(int & value, int & two)
^
1 error generated.
GCC seems to try to match up const int with int& even.
Take:
void strstripspace(float & value, float & two);
void strstripspace(int & value, int & two);
int main()
{
const int unused = 0;
const int two = 0;
strstripspace(unused, two);
return 0;
}
GCC just outputs:
<source>: In function 'int main()':
<source>:9:19: error: binding reference of type 'int&' to 'const int' discards
qualifiers
9 | strstripspace(unused, two);
| ^~~~~~
<source>:2:26: note: initializing argument 1 of 'void strstripspace(int&,
int&)'
2 | void strstripspace(int & value, int & two);
| ~~~~~~^~~~~
While clang produces:
<source>:9:5: error: no matching function for call to 'strstripspace'
strstripspace(unused, two);
^~~~~~~~~~~~~
<source>:1:6: note: candidate function not viable: no known conversion from
'const int' to 'float &' for 1st argument
void strstripspace(float & value, float & two);
^
<source>:2:6: note: candidate function not viable: 1st argument ('const int')
would lose const qualifier
void strstripspace(int & value, int & two);
^
I cannot decide if I like GCC's error message better or clang's.
More information about the Gcc-bugs
mailing list