Index: lib/Parse/ParseTentative.cpp =================================================================== --- lib/Parse/ParseTentative.cpp +++ lib/Parse/ParseTentative.cpp @@ -1494,6 +1494,10 @@ *HasMissingTypename = true; return TPResult::Ambiguous; } + if (((Tok.is(tok::amp) || Tok.is(tok::star)) && + (NextToken().is(tok::r_paren) || NextToken().is(tok::greater))) || + (Tok.is(tok::ampamp) && NextToken().is(tok::greater))) + return TPResult::True; } else { // Try to resolve the name. If it doesn't exist, assume it was // intended to name a type and keep disambiguating. Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -746,11 +746,11 @@ unsigned DiagID = diag::err_typename_missing; if (getLangOpts().MSVCCompat && isMicrosoftMissingTypename(SS, S)) DiagID = diag::ext_typename_missing; - - Diag(SS->getRange().getBegin(), DiagID) - << SS->getScopeRep() << II->getName() - << SourceRange(SS->getRange().getBegin(), IILoc) - << FixItHint::CreateInsertion(SS->getRange().getBegin(), "typename "); + if (getLangOpts().MSVCCompat || !IsTemplateName) + Diag(SS->getRange().getBegin(), DiagID) + << SS->getScopeRep() << II->getName() + << SourceRange(SS->getRange().getBegin(), IILoc) + << FixItHint::CreateInsertion(SS->getRange().getBegin(), "typename "); SuggestedType = ActOnTypenameType(S, SourceLocation(), *SS, *II, IILoc).get(); } else { Index: test/SemaTemplate/missing-typename.cpp =================================================================== --- /dev/null +++ test/SemaTemplate/missing-typename.cpp @@ -0,0 +1,101 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s -Wno-unused +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s -Wno-unused -fms-compatibility -DMSVC + +namespace PR8446_1 { +struct A { + typedef int BASE_VALUE; +}; + +void g(int &y) {} + +template +void f(int &rValue) { +#if MSVC +// expected-warning@+4 {{missing 'typename' prior to dependent type name 'BASE_CLASS::BASE_VALUE'}} +#else + // expected-error@+2 {{missing 'typename' prior to dependent type name 'BASE_CLASS::BASE_VALUE'}} +#endif + return g((BASE_CLASS::BASE_VALUE &)rValue); +} + +int main() { + int x; + f(x); + return 0; +} +} // namespace PR8446_1 + +namespace PR8446_2 { +struct site_symmetry_ops {}; + +template +struct class_ { + template + void def(A1 const &a1) {} +}; + +template +struct init { + init() {} +}; + +struct special_position_site_parameter { + typedef char scatterer_type; +}; + +template +struct valued_asu_parameter_heir_wrapper { + static class_ wrap(char const *name) { + return class_(); + } +}; + +template +struct special_position_wrapper { + static void wrap(char const *name) { + valued_asu_parameter_heir_wrapper::wrap(name) +#if MSVC + // expected-warning@+4 {{missing 'typename' prior to dependent type name 'wt::scatterer_type'}} +#else + // expected-error@+2 {{missing 'typename' prior to dependent type name 'wt::scatterer_type'}} +#endif + .def(init()); + } +}; + +void wrap_special_position() { + special_position_wrapper::wrap("special_position_site_parameter"); +} +} // namespace PR8446_2 + +namespace PR8446_3 { +int g(int); +template +int f1(int x) { + return g((T::InnerName & x) & x); +} + +template +int f2(int x) { + return g((T::InnerName & 3) & x); +} + +template +int f3(int x) { + return g((T::InnerName & (3))); +} + +template +int f4(int x) { + return g((T::InnerName * 3) & x); +} +struct A { + static const int InnerName = 42; +}; +int main() { + f1(0); + f2(0); + f3(0); + return f4(0); +} +} // namespace PR8446_3