Improve diagnostics for EvaluateAsConstantExpr (#6956)

Initialize the `Diag` field `EvalResult` to get notes from clang when
`EvaluateAsConstantExpr` fails, then emit them using clang's diagnostic
infrastructure.

Also set valid source locations in a couple places, otherwise clang's
diagnostics code crashes.
This commit is contained in:
Nicholas Bishop
2026-03-24 19:40:09 +00:00
committed by GitHub
parent e0c6800ab3
commit f9e1806c4a
3 changed files with 21 additions and 13 deletions
+9 -3
View File
@@ -80,8 +80,14 @@ constexpr int f(int a) {
}
''';
// CHECK:STDERR: fail_invalid_constant_eval.carbon:[[@LINE+4]]:19: error: failed to evaluate constexpr function call as a constant [CppConstexprEval]
// CHECK:STDERR: let a: array(i32, Cpp.f(5)) = (1, 2, 3);
// CHECK:STDERR: ^~~~~~~~
// CHECK:STDERR: fail_invalid_constant_eval.carbon:[[@LINE+10]]:26: error: call to immediate function 'f' is not a constant expression [CppInteropParseError]
// CHECK:STDERR: 21 | let a: array(i32, Cpp.f(5)) = (1, 2, 3);
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_invalid_constant_eval.carbon:[[@LINE-7]]:10: note: cannot refer to element 5 of array of 1 element in a constant expression [CppInteropParseNote]
// CHECK:STDERR: 7 | return arr[a];
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_invalid_constant_eval.carbon:[[@LINE+4]]:26: note: in call to 'f(5)' [CppInteropParseNote]
// CHECK:STDERR: 21 | let a: array(i32, Cpp.f(5)) = (1, 2, 3);
// CHECK:STDERR: | ^
// CHECK:STDERR:
let a: array(i32, Cpp.f(5)) = (1, 2, 3);