Bug 84012 - [8 regression] error: cannot convert ‘const std::shared_ptr<std::a>’ to ‘std::a*’ in return
Summary: [8 regression] error: cannot convert ‘const std::shared_ptr<std::a>’ to ‘std:...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2018-01-23 23:37 UTC by Sunil Pandey
Modified: 2018-01-24 12:06 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sunil Pandey 2018-01-23 23:37:45 UTC
This issue appear during freeorion compilation. Test case compile fine with GCC 7 and Clang 5 but fail with GCC 8.

$ cat StyleFactory.cpp
namespace std {
template <typename> class shared_ptr {};
class a;
template <class> class b {
  a *g() const;
  shared_ptr<a> e;
};
template <class f> a *b<f>::g() const { return e; }
}

$ g++ --version
g++ (GCC) 8.0.1 20180123 (experimental)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ -O2 -fPIC -std=c++11 -o StyleFactory.cpp.i.o -c StyleFactory.cpp                                             StyleFactory.cpp: In member function ‘std::a* std::b< <template-parameter-1-1> >::g() const’:
StyleFactory.cpp:8:48: error: cannot convert ‘const std::shared_ptr<std::a>’ to ‘std::a*’ in return
 template <class f> a *b<f>::g() const { return e; }
                                                ^

GCC 7 works fine.

$ g++ --version
g++ (GCC) 7.2.1 20180123
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ -O2 -fPIC -std=c++11 -o StyleFactory.cpp.i.o -c StyleFactory.cpp
$ echo $?
0

Clang 5 also work fine.

$ clang++ --version
clang version 5.0.1
Target: x86_64-unknown-linux-gnu
Thread model: posix

$ clang++ -O2 -fPIC -std=c++11 -o StyleFactory.cpp.i.o -c StyleFactory.cpp
$ echo $?
0
Comment 1 Andrew Pinski 2018-01-24 00:59:26 UTC
In this context e has a non-dependent type as shared_ptr<a> is a non-dependent type and shared_ptr<a> does not have a conversion to a*.  So I don't see why this should accepted.
Comment 2 Jakub Jelinek 2018-01-24 09:00:33 UTC
This changed with r253599.
Comment 3 Jonathan Wakely 2018-01-24 12:06:38 UTC
The code is invalid, it only works with older versions of GCC and Clang because you never instantiate the function template and so the bug isn't detected. Obviously if you try to use the function then it won't compile, because there's no conversion. Why do you expect it to compile?

See https://gcc.gnu.org/gcc-7/porting_to.html#hypothetical-instantiation