Author: Nico Weber
Date: 2026-08-20T15:48:51Z
New Revision: db34fbec8166078c24812c165df2d8770fbd3a48

URL: 
https://github.com/llvm/llvm-project/commit/db34fbec8166078c24812c165df2d8770fbd3a48
DIFF: 
https://github.com/llvm/llvm-project/commit/db34fbec8166078c24812c165df2d8770fbd3a48.diff

LOG: clang: Use the context printing policy in TemplateDiff (#217651)

TemplateDiff made a new PrintingPolicy instead of using ASTContext's.
Sema::getPrintingPolicy() tweaks ASTContext's, and sema template diffing
didn't pick up those changes.

Sema::getPrintingPolicy() does two things:

1. Something for bool vs _Bool for C (where template diffing doesn't
apply)

2. Set EntireContentsOfLargeArray to false

Before this patch, the latter had no effect in diff mode, meaning we the
same type printed differently in a diagnostic depending on if used
template diffing. Now they're consistent.

(This made no difference before https://reviews.llvm.org/D115031, which
probably just forgot to update this call site.)

Added: 
    

Modified: 
    clang/lib/AST/ASTDiagnostic.cpp
    clang/test/SemaCXX/cxx2a-nttp-printing.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index f7888f58985db..0925fbdcbaeb7 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -2114,21 +2114,15 @@ class TemplateDiff {
   }
 
 public:
-
   TemplateDiff(raw_ostream &OS, ASTContext &Context, QualType FromType,
                QualType ToType, bool PrintTree, bool PrintFromType,
                bool ElideType, bool ShowColor)
-    : Context(Context),
-      Policy(Context.getLangOpts()),
-      ElideType(ElideType),
-      PrintTree(PrintTree),
-      ShowColor(ShowColor),
-      // When printing a single type, the FromType is the one printed.
-      FromTemplateType(PrintFromType ? FromType : ToType),
-      ToTemplateType(PrintFromType ? ToType : FromType),
-      OS(OS),
-      IsBold(false) {
-  }
+      : Context(Context), Policy(Context.getPrintingPolicy()),
+        ElideType(ElideType), PrintTree(PrintTree), ShowColor(ShowColor),
+        // When printing a single type, the FromType is the one printed.
+        FromTemplateType(PrintFromType ? FromType : ToType),
+        ToTemplateType(PrintFromType ? ToType : FromType), OS(OS),
+        IsBold(false) {}
 
   /// DiffTemplate - Start the template type 
diff ing.
   void DiffTemplate() {

diff  --git a/clang/test/SemaCXX/cxx2a-nttp-printing.cpp 
b/clang/test/SemaCXX/cxx2a-nttp-printing.cpp
index d03a5dd7dd6ad..cace0bc94f390 100644
--- a/clang/test/SemaCXX/cxx2a-nttp-printing.cpp
+++ b/clang/test/SemaCXX/cxx2a-nttp-printing.cpp
@@ -7,8 +7,8 @@ template <int N> struct Str {
 
 template <Str V> class ASCII {};
 
-void Foo(ASCII<"this nontype template argument is too long to print">); // 
expected-note {{no known conversion from 'ASCII<Str<43>{"this nontype template 
argument is too long"}>' to 'ASCII<Str<52>{"this nontype template argument is 
too long to print"}>'}}
-void Bar(ASCII<"this nttp argument is too short">);                     // 
expected-note {{no known conversion from 'ASCII<Str<14>{{119, 97, 105, 116, 32, 
97, 32, 115, 27, 99, 111, 110, 100, 0}}>' to 'ASCII<Str<32>{"this nttp argument 
is too short"}>'}}
+void Foo(ASCII<"this nontype template argument is too long to print">); // 
expected-note {{no known conversion from 'ASCII<Str<43>{"this nontype template 
argument is [...]"}>' to 'ASCII<Str<52>{"this nontype template argument is 
[...]"}>'}}
+void Bar(ASCII<"this nttp argument is too short">);                     // 
expected-note {{no known conversion from 'ASCII<Str<14>{{119, 97, 105, 116, 32, 
97, 32, 115, 27, 99, ...}}>' to 'ASCII<Str<32>{"this nttp argument is too 
short"}>'}}
 void Meow(ASCII<"what|">);                                              // 
expected-note {{no known conversion from 'ASCII<Str<8>{"what??!"}>' to 
'ASCII<Str<6>{"what|"}>' for 1st argument}}
 
 void test_ascii() {


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

Reply via email to