Home > Blockchain >  VS2022 C 20 E3309 an export declaration cannot export a name with internal linkage
VS2022 C 20 E3309 an export declaration cannot export a name with internal linkage

Time:08-01

This happens when exporting a module namespace variable. It compiles and works as intended but Intellisense seems disagree. Is it an intellisense bug or a undefined behavior that has side effects?

Tried Unnamed/anonymous namespaces vs. static functions but still same error.

Env: windows11 VS2022 ISO C latest with Experimetal Module on.

employee.ixx

export module employee;

import std.core;

namespace Records {
    //raise E3309
    export const int DefaultRaiseAndDemeritAmount{ 1'000 };
}

main.cpp

import std.core;
import employee;

using namespace std;

int main()
{
    auto RaiseModifier = Records::DefaultRaiseAndDemeritAmount;
    //compiler no error and work as intended, print 1000 to console.
    cout << RaiseModifier;
}

CodePudding user response:

As usual in these cases, intellisense is incorrect. Well, the rule it cites is correct, but it is applying it where it shouldn't.

Yes, you cannot export a name with internal linkage. However, your variable doesn't have internal linkage. The rules for that have an explicit carve-out for "inline or exported" non-template const-qualified variables.

  • Related