Skip to content

C++ modules not handling internal linkage #90259

Closed
@rnikander

Description

@rnikander

In the following example code, I have two variables int abc that should be private to the files (internal linkage). They are in anonymous namespaces. But, they conflict with each other.

main.cc:

import mymod;
int main() {
    foo();
}

mymod.cppm:

module;
#include <stdio.h>
export module mymod;
export import :part1;
namespace { int abc; }
export void foo() {
    printf("In foo() %d\n", abc);
}

part1.cppm:

export module mymod:part1;
namespace { int abc; }
export void part1_fun() {}

Compiler error:

mymod.cppm:9:29: error: reference to 'abc' is ambiguous
    9 |     printf("In foo() %d\n", abc);
      |                             ^
/.../part1.cppm:4:17: note: candidate found by name lookup is '(anonymous namespace)::abc'
    4 | namespace { int abc; }
      |                 ^
mymod.cppm:6:17: note: candidate found by name lookup is '(anonymous namespace)::abc'
    6 | namespace { int abc; }
      |                 ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"clang:modulesC++20 modules and Clang Header Modules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions