[PATCH] D21508: Diagnose friend function template redefinitions

Serge Pavlov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 19 07:35:44 PDT 2018


sepavloff added a comment.

Other compilers successfully recognize errors (checked using https://godbolt.org/). For instance, the code:

  template<typename T> inline void func_35(T *x);
  template<typename T1>
  struct C35a {
    template<typename T> friend void func_35(T *x) {}
  };
  template<typename T1>
  struct C35b {
    template<typename T> friend void func_35(T *x) {}
  };
  C35a<int> v35a;
  C35b<int> v35b;

is rejected by MSVC 19:

  example.cpp
  <source>(7): error C2995: 'void func_37(T *)': function template has already been defined
  <source>(1): note: see declaration of 'func_37'
  Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25017 for x64
  Copyright (C) Microsoft Corporation.  All rights reserved.
  Compiler returned: 2

by  gcc 7.3:

  <source>:7:27: error: redefinition of 'template<class T> void func_37(T*)'
   template<typename T> void func_37(T *x) {}
                             ^~~~~~~
  <source>:1:27: note: 'template<class T> void func_37(T*)' previously declared here
   template<typename T> void func_37(T *x);
                             ^~~~~~~
  Compiler returned: 1

and icc 18:

  <source>(7): error: function template "func_37" has already been defined
    template<typename T> void func_37(T *x) {}
                              ^
  compilation aborted for <source> (code 2)
  Compiler returned: 2


Repository:
  rC Clang

https://reviews.llvm.org/D21508





More information about the cfe-commits mailing list