Detect existence of name in at least one base class
05:50 31 Dec 2025

This code (reduced from the Chromium codebase) is accepted by Clang but rejected by GCC:

template concept Concept = requires {typename T::marker;};
#define INJECT_MARKER using marker = int;
struct Base1{
    INJECT_MARKER
};
struct Base2{
    INJECT_MARKER
};

struct Derived: Base1,  Base2{};

static_assert(Concept);

GCC fails with the following error:

:12:15: error: static assertion failed
   12 | static_assert(Concept);
      |               ^~~~~~~~~~~~~~~~
  • constraints not satisfied
    • required by the constraints of 'template concept Concept'
      :1:27:   
          1 | template concept Concept = requires {typename T::marker;};
            |                           ^~~~~~~
    • in requirements  [with T = Derived]
      :1:37:   
          1 | template concept Concept = requires {typename T::marker;};
            |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • the required type 'typename T::marker' is invalid, because
      :1:56:
          1 | template concept Concept = requires {typename T::marker;};
            |                                               ~~~~~~~~~^~~~~~~~~~
    • error: lookup of 'marker' in 'Derived' is ambiguous
    • candidates are: 'using Base2::marker = int'
      :2:29:
          2 | #define INJECT_MARKER using marker = int;
            |                             ^~~~~~
    • in expansion of macro 'INJECT_MARKER'
          7 |         INJECT_MARKER
            |         ^~~~~~~~~~~~~
    •                 'using Base1::marker = int'
      :2:29:
          2 | #define INJECT_MARKER using marker = int;
            |                             ^~~~~~
    • in expansion of macro 'INJECT_MARKER'
          4 |         INJECT_MARKER
            |         ^~~~~~~~~~~~~
Compiler returned: 1

There are dozens of instances of this macro in Chromium. I cannot modify the inheritance hierarchy, which may include multiple levels (we must support detecting indirect bases).

I can modify the INJECT_MARKER macro and Concept.

Help me refactor this so that the code builds with GCC.

c++ gcc refactoring multiple-inheritance ambiguous