Consider the following snippet: template <int> struct bar {}; template <class I> auto foo(I i) -> bar<i()> { return {}; } int main() { foo([]{ return 1; }); // (0) } This compiles and works as intended on clang++5, but produces a compile-time error on g++7: prog.cc:5:25: error: template argument 1 is invalid auto foo(I i) -> bar<i()> { return {}; } ^ Live example: https://wandbox.org/permlink/6cbnRiTyphIaf2yh -- I think this is a bug because: * `[]{ return 1; }` is implicitly `constexpr`, as `1` is a "core constant expression". * In the context of the function call marked with "(0)", the argument `i` is a closure generated by the lambda expression `[]{ return 1; }`. The closure has a `constexpr operator()` overload which returns a `1` (a "core constant expression"). * `bar<i()>` is a valid "trailing return type", as `i()` can be a "core constant expression" if it results in a `constexpr` function invocation. --- Additional info, context and examples: http://stackoverflow.com/questions/43043397
Confirmed for C++17+. lambdas are only constexpr in C++17+.
Is https://stackoverflow.com/questions/76534613/ a duplicate of this?
(In reply to Roland Schulz from comment #2) > Is https://stackoverflow.com/questions/76534613/ a duplicate of this? Yes, this is in turn a dup of the older PR68495 I think *** This bug has been marked as a duplicate of bug 68495 ***