llvm-project/clang/test/AST/ast-dump-udl-consteval.cpp
zyn0217 077e1b892d
[clang] Preserve UDL nodes in RemoveNestedImmediateInvocation (#66641)
D63960 performs a tree transformation on AST to prevent evaluating
constant expressions eagerly by removing recorded immediate consteval
invocations from subexpressions. (See
https://reviews.llvm.org/D63960#inline-600736 for its motivation.)

However, the UDL node has been replaced with a CallExpr in the default
TreeTransform since ca844ab0 (inadvertently?). This confuses clangd as
it relies on the exact AST node type to decide whether or not to present
inlay hints for an expression.

With regard to the fix, I think it's enough to return the UDL expression
as-is during the transformation: We've bound it to temporary in its
construction, and there's no ConstantExpr to visit under a UDL.

Fixes https://github.com/llvm/llvm-project/issues/63898.
2023-10-04 04:45:46 -05:00

18 lines
529 B
C++

// RUN: %clang_cc1 -xc++ -std=c++23 -ast-dump %s | FileCheck %s
int inline consteval operator""_u32(unsigned long long val) {
return val;
}
void udl() {
(void)(0_u32 + 1_u32);
}
// CHECK: `-BinaryOperator {{.+}} <col:10, col:18> 'int' '+'
// CHECK-NEXT: |-ConstantExpr {{.+}} <col:10> 'int'
// CHECK-NEXT: | |-value: Int 0
// CHECK-NEXT: | `-UserDefinedLiteral {{.+}} <col:10> 'int'
// CHECK: `-ConstantExpr {{.+}} <col:18> 'int'
// CHECK-NEXT: |-value: Int 1
// CHECK-NEXT: `-UserDefinedLiteral {{.+}} <col:18> 'int'