diff options
author | Serge Pavlov <sepavloff@gmail.com> | 2017-06-21 12:46:57 +0000 |
---|---|---|
committer | Serge Pavlov <sepavloff@gmail.com> | 2017-06-21 12:46:57 +0000 |
commit | 25dbe1a16e6b0f85cb75e108d96d1bfef0c45e18 (patch) | |
tree | c939b102eca4727d8e947f9f71329385d76a0d40 /clang/lib/Sema/SemaDecl.cpp | |
parent | f81d46f45ee9d80ce13c4da81898470e2e7c2140 (diff) | |
download | llvm-25dbe1a16e6b0f85cb75e108d96d1bfef0c45e18.zip llvm-25dbe1a16e6b0f85cb75e108d96d1bfef0c45e18.tar.gz llvm-25dbe1a16e6b0f85cb75e108d96d1bfef0c45e18.tar.bz2 |
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
https://bugs.llvm.org/show_bug.cgi?id=14785:
```
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.
llvm-svn: 305903
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index d6164b3..2f78d06 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -12232,6 +12232,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, if (FD) { FD->setBody(Body); + FD->setWillHaveBody(false); if (getLangOpts().CPlusPlus14) { if (!FD->isInvalidDecl() && Body && !FD->isDependentContext() && |