https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116344

            Bug ID: 116344
           Summary: Wlto-type-mismatch and Wodr should show what TUs
                    mismatched
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arsen at gcc dot gnu.org
  Target Milestone: ---

for instance, consider the following:

// test1.h
template<typename> struct A {};

// test1.c
#include "test1.h"

namespace { A<int> a; }

// test2.h
#include "test1.h"

template<> struct A<int>
{
  int x;
};

// test2.c
#include "test2.h"
namespace { A<int> a; }

.. the compiler correctly tells us:

test1.h:1:27: warning: type ‘struct A’ violates the C++ One Definition Rule
[-Wodr]
    1 | template<typename> struct A {};
      |                           ^
test2.h:3:19: note: a different type is defined in another translation unit
    3 | template<> struct A<int>
      |                   ^
test2.h:5:7: note: the first difference of corresponding definitions is field
‘x’
    5 |   int x;
      |       ^
test2.h:3:19: note: a type with different number of fields is defined in
another translation unit
    3 | template<> struct A<int>
      |                   ^

... but all the locations are in header files.  these header files could be
occurring many times, so it might be difficult to tell where they're included
from.

it'd be nice if GCC could say, for instance,

test1.h:1:27: warning: type ‘struct A’ violates the C++ One Definition Rule
[-Wodr]
    1 | template<typename> struct A {};
      |                           
test1.h:1:2: note: in the translation unit for test1.c  //<-
test2.h:3:19: note: a different type is defined in another translation unit
    3 | template<> struct A<int>
      |                   ^
test2.h:5:7: note: the first difference of corresponding definitions is field
‘x’
    5 |   int x;
      |       ^
test2.h:3:19: note: a type with different number of fields is defined in
another translation unit
    3 | template<> struct A<int>
      |                   ^
      |                           
test1.h:1:2: note: in the translation unit for test2.c  //<-

... or the usual "included from" chain, or somesuch.  unsure what the best
approach is, but in general it'd be handy to know at least a pair of mismatched
TUs to be able to debug further

Reply via email to