On Tue, Jun 19, 2018 at 6:04 AM, Jonathan Wakely <jwakely....@gmail.com> wrote: > On Tue, 19 Jun 2018 at 01:30, Soul Studios wrote: >> >> > >> > It's never called. >> > >> > I added a call to abort() to that function, and the tests all pass. So >> > the function is never used, so GCC never compiles it and doesn't >> > notice that the return type is invalid. That's allowed by the >> > standard. The compiler is not required to diagnose ill-formed code in >> > uninstantiated templates. >> > >> >> >> UPDATE: My bad. >> The original compiler feature detection on the test suite was broken/not >> matching the correct libstdc++ versions. >> Hence the emplace_back/emplace_front tests were not running. > > Told you so :-P > > >> However, it does surprise me that GCC doesn't check this code. > > It's a dependent expression so can't be fully checked until > instantiated -- and as you've discovered, it wasn't being > instantiated. There's a trade-off between compilation speed and doing > additional work to check uninstantiated templates with arbitrarily > complex expressions in them.
And specifically, &<type-dependent expression> might use an overloaded operator& that returns a reference, so it might be possible to have a valid instantiation, so the compiler must not reject the template. Jason