Skip to content

Commit

Permalink
Add some null asserts, closes #1134
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hsutter committed Jun 22, 2024
1 parent 893c9aa commit f429962
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion source/sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit f429962

Please sign in to comment.