[Bug c++/87293] New: An object with invalid type is treated as if it were of type int when reporting errors
b7.10110111 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Sep 13 12:16:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87293
Bug ID: 87293
Summary: An object with invalid type is treated as if it were
of type int when reporting errors
Product: gcc
Version: 8.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: b7.10110111 at gmail dot com
Target Milestone: ---
Consider the following C++ code:
//--------------------------------
#include <memory>
int main()
{
std::shared_ptr<dbl> p(new double{5.3});
}
//--------------------------------
Here, g++ emits the following messages:
------------------BEGIN---------------------
test.cpp: In function ‘int main()’:
test.cpp:4:21: error: ‘dbl’ was not declared in this scope
std::shared_ptr<dbl> p(new double{5.3});
^~~
test.cpp:4:24: error: template argument 1 is invalid
std::shared_ptr<dbl> p(new double{5.3});
^
test.cpp:4:43: error: invalid conversion from ‘double*’ to ‘int’ [-fpermissive]
std::shared_ptr<dbl> p(new double{5.3});
^
-----------------END-----------------------
The first error is correct: there's no dbl type. But the last error makes no
sense at all. There's nothing in the code which could imply that the type of
`p` could be `int`: even if there were no type present, C++ is not C89 to imply
`int` by default.
Moreover, if we add a line which uses `p` in another erroneous way, e.g.
"struct S{}s=p;", g++ again thinks that `p` is of type `int` ("error:
conversion from ‘int’ to non-scalar type ‘main()::S’ requested").
More information about the Gcc-bugs
mailing list