[PATCH] D30170: Function definition may have uninstantiated body

Serge Pavlov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 20 08:15:26 PST 2017


sepavloff created this revision.

Current implementation of `FunctionDecl::isDefined` does not take into
account declarations that do not have a body, but it can be instantiated
from a templated definition. This behavior creates problems when
processing friend functions defined in class templates. For instance,
the code:

  template<typename T> struct X { friend void f() {} };
  X<int> xi;
  void f() {}

compiles successfully but must fail due to redefinition of `f`. The
declaration of the friend `f` is created when the containing template
`X` is instantiated, but it does not have a body as per 14.5.4p4
because `f` is not odr-used.

With this change the function `Sema::CheckForFunctionRedefinition`
considers functions with uninstantiated bodies as definitions.


https://reviews.llvm.org/D30170

Files:
  include/clang/AST/Decl.h
  lib/AST/Decl.cpp
  lib/Sema/SemaDecl.cpp
  test/SemaCXX/friend2.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30170.89125.patch
Type: text/x-patch
Size: 7921 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170220/94061265/attachment.bin>


More information about the cfe-commits mailing list