https://github.com/ChuanqiXu9 created 
https://github.com/llvm/llvm-project/pull/187446

Inspired by https://github.com/clangd/clangd/issues/2589

it seems like we lost the flag for "-std=c++26" there and we meet odd error 
messgae like the std ver is not correct. and it turns out we simply didn't 
interpret .cppm file as C++ in some corner of the codebase.

>From f7ac27d7cd4272831ff4c95b16bf1fd18603f013 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu <[email protected]>
Date: Thu, 19 Mar 2026 15:05:04 +0800
Subject: [PATCH] [CompilationDatabase] Treat .cppm file as C++ in
 InterpolatingCompilationDatabase

Inspired by https://github.com/clangd/clangd/issues/2589

it seems like we lost the flag for "-std=c++26" there and we meet
odd error messgae like the std ver is not correct. and it turns out
we simply didn't interpret .cppm file as C++ in some corner of the
codebase.
---
 clang/lib/Tooling/InterpolatingCompilationDatabase.cpp | 2 ++
 clang/unittests/Tooling/CompilationDatabaseTest.cpp    | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp 
b/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
index f8306a6ad6e90..e79976703546f 100644
--- a/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
+++ b/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
@@ -111,6 +111,8 @@ static types::ID foldType(types::ID Lang) {
     return types::TY_ObjC;
   case types::TY_CXX:
   case types::TY_CXXHeader:
+  case types::TY_CXXModule:
+  case types::TY_PP_CXXModule:
     return types::TY_CXX;
   case types::TY_ObjCXX:
   case types::TY_ObjCXXHeader:
diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp 
b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index 2d68e0994c93e..93f598e992c9c 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -847,6 +847,11 @@ TEST_F(InterpolateTest, Language) {
             "clang -D dir/aux.cpp -x objective-c++-header -std=c++17");
 }
 
+TEST_F(InterpolateTest, CXX20Modules) {
+  add("dir/foo.cpp", "-std=c++20");
+  EXPECT_EQ(getCommand("dir/foo.cppm"), "clang -D dir/foo.cpp -std=c++20");
+}
+
 TEST_F(InterpolateTest, Strip) {
   add("dir/foo.cpp", "-o foo.o -Wall");
   // the -o option and the input file are removed, but -Wall is preserved.

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to