Function with unparsed body is a definition


Function with unparsed body is a definition

While a function body is being parsed, the function declaration is not considered
as a definition because it does not have a body yet. In some cases it leads to
incorrect interpretation, the case is presented in

    template<typename T> struct Somewhat {
      void internal() const {}
      friend void operator+(int const &, Somewhat<T> const &) {}
void operator+(int const &, Somewhat<char> const &x) { x.internal(); }

When statement x.internal() in the body of global operator+ is parsed, the type
of x must be completed, so the instantiation of Somewhat<char> is started. It
instantiates the declaration of operator+ defined inline, and makes a check for
redefinition. The check does not detect another definition because the declaration
of operator+ is still not defining as does not have a body yet.

To solves this problem the function isThisDeclarationADefinition considers
a function declaration as a definition if it has flag WillHaveBody set.

This change fixes PR14785.

Differential Revision: https://reviews.llvm.org/D30375

This is a recommit of 305379, reverted in 305381, with small changes.


sepavloffJun 21 2017, 5:46 AM
Differential Revision
D30375: Function with unparsed body is a definition
rL305902: Fixed compiler warnings after r305890.