microsoft / microsoft/STL

<variant>: Failed to use an empty class as template parameter

Open
#5,254 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug compiler modules
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

Describe the bug

To compile the following file:

  1. Comment line 1 module; and line 4 export module Module; so that don't treat this file as an interface module unit and compile successfully.
  2. Uncomment line 7 int a; to add a member to class Dummy and compile successfully.

Or it can't be compiled due to internal compiler error.

Command-line test case

repro.ixx

module;
#include <variant>

export module Module;

struct Dummy{
	//int a;
};

using WrappedDummy = std::variant<Dummy>;

template<const WrappedDummy&>
struct Container {};

constexpr auto nttp = WrappedDummy{};

constexpr auto var = Container<nttp>{};
C:\Temp>cl /std:c++latest .\repro.ixx
Microsoft (R) C/C++ Optimizing Compiler Version 19.42.34436 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

/std:c++latest is provided as a preview of language features from the latest C++
working draft, and we're eager to hear about bugs and suggestions for improvements.
However, note that these features are provided as-is without support, and subject
to changes or removal as the working draft evolves. See
https://go.microsoft.com/fwlink/?linkid=2045807 for details.

.\repro.ixx(18): fatal error C1001: Internal compiler error.
(compiler file 'msc1.cpp', line 1599)
 To work around this problem, try simplifying or changing the program near the locations listed above.
If possible please provide a repro here: https://developercommunity.visualstudio.com 
Please choose the Technical Support command on the Visual C++ 
 Help menu, or open the Technical Support help file for more information
INTERNAL COMPILER ERROR in 'H:\Program Files\Microsoft Visual Studio\VC\Tools\MSVC\14.42.34433\bin\HostX64\x64\CL.exe'
    Please choose the Technical Support command on the Visual C++
    Help menu, or open the Technical Support help file for more information

Expected behavior

compile successfully

STL version

Microsoft Visual Studio Community 2022
Version 17.12.4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by compiling the provided repro.ixx with the documented /std:c++latest command and confirm the internal compiler error at line 18. Investigate the interaction between std::variant, an empty Dummy class, module units, and a non-type template parameter; done means the file compiles successfully without the C1001 error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.