[PATCH] D30375: Function with unparsed body is a definition
Serge Pavlov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 25 00:24:37 PST 2017
sepavloff created this revision.
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.
This change solves this problem by using flag `WillHaveBody`. It introduces new
semantic action `ActOnStartFunctionBody`, which set this flag so that definitions
that do not have body (such as deleted functions) do not have this flag.
This change fixes PR14785.
The fix requires https://reviews.llvm.org/D26065 be applied otherwise diagnostics is awful.
https://reviews.llvm.org/D30375
Files:
include/clang/AST/Decl.h
include/clang/Sema/Sema.h
lib/AST/Decl.cpp
lib/Parse/Parser.cpp
lib/Sema/SemaCUDA.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaCXX/friend2.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30375.89779.patch
Type: text/x-patch
Size: 4981 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170225/e7ccd6a6/attachment.bin>
More information about the cfe-commits
mailing list