mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 07:54:41 +01:00
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:
+9
-3
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user