Skip to content

False Positive of ODR Violation for Functions with Internal Linkage in Modules #137533

Open
@ckwastra

Description

@ckwastra

Code (CE):

  • m.cpp:

    module;
    #include <cstdio>
    export module m;
    static void f() { std::puts(__FILE__); }
    export auto &fr = f;
  • main.cpp:

    #include <cstdio>
    import m;
    static void f() { std::puts(__FILE__); }
    constexpr auto &fr1 = f;
    auto &fr2 = fr;
    int main() {
      fr1();
      fr2();
    }

Clang raises the following error:

m.cpp:4:13: error: 'f' has different definitions in different modules; definition in module 'm' first difference is function body
    4 | static void f() { std::puts(__FILE__); }
      | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:3:13: note: but in '' found a different body
    3 | static void f() { std::puts(__FILE__); }
      | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

GCC accepts the code (as expected), and running the produced executable outputs:

/app/main.cpp
/app/m.cpp

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:modulesC++20 modules and Clang Header Modulesfalse-positiveWarning fires when it should not

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions