[PATCH] D16989: Change interpretation of function definition in friend declaration of template class.

Serge Pavlov via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 29 11:33:15 PDT 2016


sepavloff marked an inline comment as done.

================
Comment at: lib/Sema/SemaDecl.cpp:8657-8658
@@ +8656,4 @@
+  DeclContext *SemanticDC = D->getDeclContext();
+  if (SemanticDC->isDependentContext())
+    return false;
+  // Get here only for out-of-line declarations: lexical context is dependent,
----------------
rsmith wrote:
> I don't think this is right. Given:
> 
>   template<typename T> void f() {
>     extern void g();
>     extern void g();
>   }
> 
> ... we do want to link the two declarations of `g` together. We even want to link them to a prior declaration of `::g` if there is one, since they have a non-dependent type, otherwise we'll reject cases like:
> 
>   void g();
>   constexpr void (*p)() = g;
>   template<bool> struct X { typedef int type; };
>   template<typename T> void f() {
>     extern void g();
>     X<&g == p>::type n; // note: no 'typename' required, not value-dependent,
>   }                     // must evaluate to 'true' while parsing the template
> 
> Perhaps we're trying to make this check too general, and we should instead only make this new logic apply to the case of friend declarations. Are there any cases where a friend declaration in a dependent context that names a non-member function needs to be added to the redeclaration chain?
It is convenient to have single function for both friend and forward declarations, as it is called from the point where both cases may be observed.

It looks like there is no mandatory requirement to add a friend declaration in a dependent context to the redeclaration chain, because ill-formed program will be detected during instantiation of enclosing template class. But making so allows to detect some problems earlier.


https://reviews.llvm.org/D16989





More information about the cfe-commits mailing list