microsoft / microsoft/vscode-cpptools

Errors if I use char[] string inisialisation using std::filesystem::path

Open
#11,377 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug Language Service Visual Studio
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Environment
  • OS and Version: Windows 11 22H2
  • VS Code Version: 1.81.1
  • C/C++ Extension Version: 1.17.5

I use Clang 16.0.5 under MSYS2 enviroment (Clang profile (UCRT runtime))

Bug Summary and Steps to Reproduce

Using anonymous std::string initialization using std::filesystem::path, VS Code shows an error; however, I can successfully compile my project without any warnings or errors.

Example:

            std::filesystem::path path1{"mypath.ext"};
            std::filesystem::path path2(std::string("mypath.ext"));

            std::filesystem::path path3 = path2 / "some";

            std::filesystem::path path4 = path2;
            path4.replace_extension(".ext");

path1:

[{
	"resource": "/c:/Users/alekesej/Documents/Programming/app3d/src/app3d/io/asset.cpp",
	"owner": "C/C++: IntelliSense",
	"code": "289",
	"severity": 8,
	"message": "no instance of constructor \"std::__1::__fs::filesystem::path::path\" matches the argument list",
	"source": "C/C++",
	"startLineNumber": 339,
	"startColumn": 40,
	"endLineNumber": 339,
	"endColumn": 40,
	"relatedInformation": [
		{
			"startLineNumber": 339,
			"startColumn": 40,
			"endLineNumber": 339,
			"endColumn": 40,
			"message": "argument types are: (const char [11])",
			"resource": "/C:/Users/alekesej/Documents/Programming/app3d/src/app3d/io/asset.cpp"
		}
	]
}]

path2 works;
path3:

[{
	"resource": "/c:/Users/alekesej/Documents/Programming/app3d/src/app3d/io/asset.cpp",
	"owner": "C/C++: IntelliSense",
	"code": "349",
	"severity": 8,
	"message": "no operator \"/\" matches these operands",
	"source": "C/C++",
	"startLineNumber": 342,
	"startColumn": 49,
	"endLineNumber": 342,
	"endColumn": 49,
	"relatedInformation": [
		{
			"startLineNumber": 342,
			"startColumn": 49,
			"endLineNumber": 342,
			"endColumn": 49,
			"message": "operand types are: std::__1::__fs::filesystem::path / const char [5]",
			"resource": "/C:/Users/alekesej/Documents/Programming/app3d/src/app3d/io/asset.cpp"
		},
		{
			"startLineNumber": 342,
			"startColumn": 49,
			"endLineNumber": 342,
			"endColumn": 49,
			"message": "function \"std::__1::__fs::filesystem::operator/\" does not match because argument #2 does not match parameter",
			"resource": "/C:/Users/alekesej/Documents/Programming/app3d/src/app3d/io/asset.cpp"
		},
		{
			"startLineNumber": 342,
			"startColumn": 49,
			"endLineNumber": 342,
			"endColumn": 49,
			"message": "built-in operator/(<promoted arithmetic>, <promoted arithmetic>) does not match because argument #1 does not match parameter",
			"resource": "/C:/Users/alekesej/Documents/Programming/app3d/src/app3d/io/asset.cpp"
		}
	]
}]

path4:

[{
	"resource": "/c:/Users/alekesej/Documents/Programming/app3d/src/app3d/io/asset.cpp",
	"owner": "C/C++: IntelliSense",
	"code": "415",
	"severity": 8,
	"message": "no suitable constructor exists to convert from \"const char [5]\" to \"std::__1::__fs::filesystem::path\"",
	"source": "C/C++",
	"startLineNumber": 345,
	"startColumn": 37,
	"endLineNumber": 345,
	"endColumn": 37
}]

In all cases, if I replace "mystring" with std::string(mystring) it errors will disappear.

Configuration and Logs

In the debug log, I didn't see any details about it. Environment info:


loggingLevel: Debug
cpptools version (TypeScript): 1.17.5
cpptools version (native): 1.17.5.0
Autocomplete is enabled.
Error squiggles are enabled if all header dependencies are resolved.
Hover is enabled.
IntelliSense Engine = default.
LSP: cpptools/queryCompilerDefaults (id: 1)
Querying compiler for default C++ language standard using command line: C:\msys64\clang64\bin\gcc.exe -x c++ -E -dM nul
LSP: cpptools/didChangeCppProperties (id: 2)
LSP: cpptools/queryCompilerDefaults (id: 3)
Detected language standard version: c++17
Querying compiler's default target using command line: "C:\msys64\clang64\bin\gcc.exe" -dumpmachine
Compiler returned default target value: x86_64-w64-windows-gnu
Compiler query command line: C:\msys64\clang64\bin\gcc.exe -std=c17 -m64 -Wp,-v -fno-blocks -E -dM -x c nul
Attempting to get defaults from C compiler in "compilerPath" property: 'C:\msys64\clang64\bin\gcc.exe'
Compiler query command line: C:\msys64\clang64\bin\gcc.exe -std=c++17 -m64 -Wp,-v -fno-blocks -E -dM -x c++ nul
Attempting to get defaults from C++ compiler in "compilerPath" property: 'C:\msys64\clang64\bin\gcc.exe'
Code browsing service initialized
Querying compiler for default C++ language standard using command line: C:\msys64\clang64\bin\clang++.exe -x c++ -E -dM nul
Custom configuration provider 'CMake Tools' registered
Detected language standard version: c++17
Querying compiler's default target using command line: "C:\msys64\clang64\bin\clang++.exe" -dumpmachine
Compiler returned default target value: x86_64-w64-windows-gnu
Compiler query command line: C:\msys64\clang64\bin\clang++.exe -std=c++23 -m64 -Wp,-v -fno-blocks -E -dM -x c++ nul
Compiler query command line: C:\msys64\clang64\bin\clang++.exe -std=c++2b -m64 -Wp,-v -fno-blocks -E -dM -x c++ nul
LSP: cpptools/fileCreated: file:///c%3A/Users/alekesej/Documents/Programming/app3d/build/.cmake/api/v1/reply/cache-v2-e71d07b676ecc0c638a3.json
LSP: cpptools/fileCreated: file:///c%3A/Users/alekesej/Documents/Programming/app3d/build/.cmake/api/v1/reply/codemodel-v2-6a6e32ecd3a4c1d44d8e.json
LSP: cpptools/fileCreated: file:///c%3A/Users/alekesej/Documents/Programming/app3d/build/.cmake/api/v1/reply/index-2023-08-29T10-30-35-0049.json
LSP: cpptools/fileCreated: file:///c%3A/Users/alekesej/Documents/Programming/app3d/build/.cmake/api/v1/reply/target-app3d-Debug-1e7eed5e9f8692b7c018.json
LSP: cpptools/fileDeleted: file:///c%3A/Users/alekesej/Documents/Programming/app3d/build/.cmake/api/v1/reply/cache-v2-88c650da2ea2b8a70cfb.json
LSP: cpptools/fileDeleted: file:///c%3A/Users/alekesej/Documents/Programming/app3d/build/.cmake/api/v1/reply/index-2023-08-29T10-12-55-0139.json
LSP: cpptools/fileDeleted: file:///c%3A/Users/alekesej/Documents/Programming/app3d/build/.cmake/api/v1/reply/codemodel-v2-ecd965f35361ae2e590c.json
LSP: cpptools/fileDeleted: file:///c%3A/Users/alekesej/Documents/Programming/app3d/build/.cmake/api/v1/reply/target-app3d-Debug-b425a7ad3f8aa23defc2.json
Attempting to get defaults from C++ compiler in "compilerPath" property: 'C:\msys64\clang64\bin\clang++.exe'
Compiler query command line: C:\msys64\clang64\bin\clang++.exe -std=c17 -m64 -Wp,-v -fno-blocks -E -dM -x c nul
Attempting to get defaults from C compiler in "compilerPath" property: 'C:\msys64\clang64\bin\clang++.exe'
  Folder: C:/MSYS64/CLANG64/INCLUDE/ will be indexed
  Folder: C:/MSYS64/CLANG64/LIB/CLANG/16/INCLUDE/ will be indexed
  Folder: C:/USERS/ALEKESEJ/DOCUMENTS/PROGRAMMING/APP3D/ will be indexed
Custom browse configuration received: {
  "browsePath": [
    /// Many items
  ],
  "compilerPath": "c:/msys64/clang64/bin/clang++.exe",
  "compilerArgs": [],
  "compilerFragments": [
    " -stdlib=libc++ -fexperimental-library -g",
    "-std=c++2b"
  ]
}

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 reproducing the diagnostics in asset.cpp with the shown C++17/C++23 compiler configurations, MSYS2 Clang setup, and CMake Tools provider. Compare IntelliSense's handling of std::filesystem::path construction, path concatenation, and replace_extension with the compiler's successful results; done means the valid expressions no longer show error squiggles.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.