[cfe-dev] Bug in VarDecl::getActingDefinition()?

Tom Honermann thonermann at coverity.com
Wed Jun 10 19:55:11 PDT 2015

VarDecl::getActingDefinition() is currently defined as:

1952 VarDecl *VarDecl::getActingDefinition() {
1953   DefinitionKind Kind = isThisDeclarationADefinition();
1954   if (Kind != TentativeDefinition)
1955     return nullptr;
1957   VarDecl *LastTentative = nullptr;
1958   VarDecl *First = getFirstDecl();
1959   for (auto I : First->redecls()) {
1960     Kind = I->isThisDeclarationADefinition();
1961     if (Kind == Definition)
1962       return nullptr;
1963     else if (Kind == TentativeDefinition)
1964       LastTentative = I;
1965   }
1966   return LastTentative;
1967 }

Given C source input:

extern const char *v;
const char *v;

isThisDeclarationADefinition() returns DeclarationOnly for the former 
(because it has a non-static storage-class specifier, C11 6.9.2p2) and 
TentativeDefinition for the latter.

When getActingDefinition() is called on the VarDecl for the first 
declaration, NULL is returned.  When called on the VarDecl for the 
second, the result is the VarDecl for the second declaration.

I suspect the condition at line 1954 should be 'Kind == Definition'. 
This would be consistent with line 1961 (Kind == DeclarationOnly should 
not abort the search).


More information about the cfe-dev mailing list