weird code analysis behavior for c++ module

I created a sample project that uses traditional forward declarations in a module interface unit with its implementation. The project builds and runs without issues, and Visual Studio's built in code analysis tools report no errors. However, ReSharper’s code analysis reports an ‘ambiguous symbol’ C++ compiler warning (or error).

ReSharper’s IntelliSense also detects two ‘InClass’ types, resulting in ambiguity.

 

If I switch the IntelliSense engine to Visual Studio’s and turn off ‘code analysis’, the ambiguity issue disappears.

I hope to hear some good news about resolving this issue.

 

attached sample project at:

Upload ID: 2025_10_14_7bz7i1jrGTPNn8oSMfEdHf 

 

version:

 

 

 

 

0
9 comments

Hello,

R# found a bug for you. All declarations of an entity should be attached to the same module, see “Module ownership” on this page. You have InClass attached to the global module fragment and to Module. GCC also reports ambiguous class error - https://godbolt.org/z/r3v41M48a. See also this post - https://abuehl.github.io/2025/03/10/modules-forward-declarations.html.

0

The ambiguity seems to come from the use of the ‘export’ keyword. What is the correct way to forward declare a class declared in a ‘traditional header file’ from a module interface file?

 

0

Although everything my colleague wrote in the start comment is correct, and this is the reason why the current version of ReSharper gives the error, I am not absolutely sure that the code in the  goldbolt example is wrong. I'd say that this question is underspecified in the C++ standard, that's why GCC and ReSharper on the one hand and MSVC and Clang on the other hand treat this code differently. I decided to change the behavior in ReSharper, so in a future version it will match MSVC and Clang behavior.

The ambiguity seems to come from the use of the export keyword.

The `export` keyword is certainly needed, without it all compilers (Clang since the last version 21) agree that the code is wrong: (with export: https://godbolt.org/z/z9c3hTEMP, without export: https://godbolt.org/z/sWG59TE68).

What is the correct way to forward declare a class declared in a ‘traditional header file’ from a module interface file?

Export forward declaration should be wrapped into extern “C++”: https://godbolt.org/z/x74Yo76z8, in the such case declared `InClass` will be attached to the global module and so there won't be any ambiguity. 

0

Hi Andrey,

Thank you for the tip about using the extern keyword for forward declarations, which resolved the issue when I forward declared a class within a header file from a module.


However, if you forward declare each other's classes in both a module and a header, ambiguity still occurs.

We use this pattern frequently in our in-house code, so it’s very important that there are no issues when using ReSharper++.


You mentioned, “so in a future version it will match MSVC and Clang behavior.”
Can I expect these changes to also resolve this ambiguity?

 

Here’s a new sample project located at:

Upload ID: 2025_10_22_MDF1Hqpi3LUf7EsGaKd7VC

 

Thanks in advance

 

 

0

Hi,

Can I expect these changes to also resolve this ambiguity?

Yes, the case from your latest attach will be resolved also.

0

Hi,

Could you let me know the ETA for that changes?

Tia

 

0

It will be in the next release 2026.1, i.e. in the first half of the next year. 2026.1 EAP should start earlier.

0

After updating to the version below, it seems the issue has been resolved. Could you confirm this?

JetBrains ReSharper 2026.1

Build 261.0.20260327.174026 built on 2026-03-27

 

0

Yes, the issue is resolved in ReSharper 2026.1.

0

Please sign in to leave a comment.