https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101435
Bug ID: 101435 Summary: Bad error with missing typename keyword Product: gcc Version: 11.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: tobi at gcc dot gnu.org Target Milestone: --- Consider (https://godbolt.org/z/hxnv779Tr): =================================== template<typename U, int dim> class X { public: U v; using Scalar = U; static constexpr auto Dim = dim; explicit X(U x) : v(x) {} template<typename T> X<T, dim> cast() { return X<T, dim>(T{v}); } }; void f(int err) { auto propertyHelper = [err]<typename M>(M&& fallback) -> M { using FloatM = X<float, M::Dim>; FloatM v{0}; return err == 0 ? M{ v.cast<typename M::Scalar>() } : fallback; }; } ================================ This gives the fairly confusing error messages: +++++++++++++++++++++++++++++++ <source>: In lambda function: <source>:23:28: error: expected primary-expression before '{' token 23 | return err == 0 ? M{ v.cast<typename M::Scalar>() } : fallback; | ^ <source>:23:28: error: expected ':' before '{' token 23 | return err == 0 ? M{ v.cast<typename M::Scalar>() } : fallback; | ^ | : <source>:23:28: error: expected primary-expression before '{' token <source>:23:28: error: expected ';' before '{' token 23 | return err == 0 ? M{ v.cast<typename M::Scalar>() } : fallback; | ^ | ; <source>:23:55: error: expected '(' before '>' token 23 | return err == 0 ? M{ v.cast<typename M::Scalar>() } : fallback; | ^ | ( <source>:23:57: error: expected primary-expression before ')' token 23 | return err == 0 ? M{ v.cast<typename M::Scalar>() } : fallback; | ^ <source>:23:58: error: expected ';' before '}' token 23 | return err == 0 ? M{ v.cast<typename M::Scalar>() } : fallback; | ^~ | ; <source>:23:61: error: expected primary-expression before ':' token 23 | return err == 0 ? M{ v.cast<typename M::Scalar>() } : fallback; | ^ Compiler returned: 1 +++++++++++++++++++++++++++++++ The actual cause of the error is the missing typename keyword before M (clang points this out correctly, MSVC of course accepts the code without error message). This is similar to #63392 but in that case we at least get a hint as to what the actual problem is.