From f42996298e5f68b409de9b7b0a9404ffe4bb793f Mon Sep 17 00:00:00 2001 From: Herb Sutter Date: Sat, 22 Jun 2024 11:31:38 -1000 Subject: [PATCH] Add some null asserts, closes #1134 Adding `assert(object_type);` silences a null-dereference warning when compiling cppfront on GCC 14 using -Werror=nonnull -O2 (both switches together) Running all regression tests doesn't fire the assertion, but it's good hygiene to have it there anyway. GCC could be diagnosing a real error that I don't see, and that happens not to be exercised by the regression tests. At least now with the assertion we'll get a clear ICE to track down, if we ever do encounter a source file where it does fire. --- source/sema.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/sema.h b/source/sema.h index 302c57989..2f8a0f158 100644 --- a/source/sema.h +++ b/source/sema.h @@ -1518,9 +1518,13 @@ class sema auto check(parameter_declaration_node const& n) -> bool { + assert(n.declaration); + auto type_name = std::string{}; if (n.declaration->has_declared_return_type()) { - type_name = n.declaration->get_object_type()->to_string(); + auto object_type = n.declaration->get_object_type(); + assert(object_type); + type_name = object_type->to_string(); } if (