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

            Bug ID: 119097
           Summary: Modules references internal linkage entity
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hypengwip at gmail dot com
  Target Milestone: ---

When a variable is declared inside an unnamed namespace in a header file and
then used in a struct definition, it causes a compilation error due to internal
linkage. The issue occurs when the struct is used both in a header (.h) and
inside a module (.cppm).  

However, using the same variable in a function inside a module (.cppm) does not
produce any error.

```
// error: ‘struct A’ references internal linkage entity 'constexpr const int
{anonymous}::default_val'`

// part1.h


#pragma once

namespace {
static constexpr const int default_val { 0 };
}


// if define A here
struct A {
 int value { default_val }; // failed
 A() : value(default_val) {} // failed
 static auto a() { return default_val; } // failed
};


// part1.cppm

module;
#include "part1.h"
export module mymod;


// if define A here
struct A {
 int value { default_val }; // failed
 A() : value(default_val) {} // ok
 static auto a() { return default_val; } // ok
};

export auto a() { return default_val; } // ok

export void part1_fun(A) {}
```

Reply via email to