Skip to content

<fstream>: Importing as a header unit leads to error C2079: undefined class 'std::basic_ofstream<char,std::char_traits<char>>' #3112

@orikama

Description

@orikama

After updating to Visual Studio 17.4.0 Preview 2.0 using <fstream> as a header unit leads to compilation error.

Text.ixx

export module Test;

// Importing <filesystem> and/or <string> with <fstream> leads to compilation error.
// But importing <fstream> without <filsystem> and <string> or importing it first works.
import <filesystem>;
import <string>;
import <fstream>;

export class Test
{
    std::ofstream stream;
};

main.cpp

import Test;

int main()
{
    Test t;
}

Command-line test case

D:\test> cl /std:c++20 /EHsc /exportHeader /headerName:angle fstream string filesystem
Microsoft (R) C/C++ Optimizing Compiler Version 19.34.31823.3 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

fstream
string
filesystem

D:\test> cl /c /std:c++20 /EHsc .\Test.ixx .\main.cpp /headerUnit:angle fstream=.\fstream.ifc /headerUnit:angle string=.\string.ifc /headerUnit:angle filesystem=.\filesystem.ifc
Microsoft (R) C/C++ Optimizing Compiler Version 19.34.31823.3 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

Test.ixx
main.cpp
D:\test\Test.ixx(12): error C2079: 'Test::stream' uses undefined class 'std::basic_ofstream<char,std::char_traits<char>>'
Generating Code...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompilerCompiler work involvedfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions