0

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;
}
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • I tested the code you posted and there is no error you said, how to reproduce it? When using modules, intellisense often fails, I suggest you report this problem to [DC](https://developercommunity.visualstudio.com/search?space=8). – Yujian Yao - MSFT Jul 28 '22 at 00:04

1 Answers1

1

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982