[cfe-dev] MS-Incompatibility regarding "typename" in dependent context

Keane, Erich via cfe-dev cfe-dev at lists.llvm.org
Tue Jan 31 15:55:34 PST 2017


I'm currently working on a MS compatibility bug that I am pretty stuck with, that I was hoping someone could give me a hand on how to figure out.  This is currently blocking MySQL from building in MS compatibility mode.  First, the reproducer:

template<class T> struct Struct{ 
  typedef int TypeDef;
};

template<class TMP> void foo() {
  Struct<TMP>::TypeDef varname;
}

void foo2()
{ 
  foo<int>();
}

The result is: 
typename_test.cpp:8:9: error: expected ';' after expression
  Struct<TMP>::TypeDef varname;

This is due to Parser::ParseStatementOrDeclarationAfterAttributes (ParseStmt.cpp:152) deciding that it is an expression.  I've dug into this, and I see it go into the case tok::identifier's branch "Next.isNot(tok::coloncolon)".  Inside that, TryAnnotateName annotates the Tok token as "annot_primary_expr".  

I would expect it to be annot_typename or something similar, such that the call to isCXXDeclarationSpecifier (via isDeclarationStatement()) succeeds.

So I guess my question is:  Am I better off trying to comprehend this functionality in TryAnnotateName, or just alter isCXXDeclarationSpecifier to give a different answer?  Is there a better option that I'm missing? 

Also, can anyone give me a tip on how to begin with either?  I'm in a little bit of a foreign land attempting to mess with parsing this much.

Thanks,
Erich



More information about the cfe-dev mailing list