Skip to content

Commit

Permalink
Fixed expression API to return const symbol_t& where GCC-13 complai…
Browse files Browse the repository at this point in the history
…ns about possible dangling
  • Loading branch information
mikucionisaau committed Sep 22, 2023
1 parent 15acb20 commit 57e50fd
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions cmake/doctest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ else(doctest_FOUND)
message(STATUS "Failed to find doctest, going to make it from scratch.")
include(FetchContent)
set(DOCTEST_WITH_TESTS OFF CACHE BOOL "doctest tests")
set(DOCTEST_WITH_MAIN_IN_STATIC_LIB ON CACHE BOOL "static lib (cmake target) with a default main entry point")
set(DOCTEST_NO_INSTALL ON CACHE BOOL "Skip the installation process")
set(DOCTEST_USE_STD_HEADERS OFF CACHE BOOL "Use std headers")
FetchContent_Declare(doctest
GIT_REPOSITORY git@github.com:doctest/doctest.git
GIT_TAG v2.4.11
Expand Down
2 changes: 1 addition & 1 deletion getlibs/getlibs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ for target in "$@" ; do
echo -e "${BW}${target}: Configuring ${DOCTEST}${NC}"
cmake -S "$SOURCE/$DOCTEST" -B "$BUILD" -DCMAKE_TOOLCHAIN_FILE="$PROJECT_DIR/cmake/toolchain/${target}.cmake" \
-DCMAKE_PREFIX_PATH="$LIBS" -DCMAKE_INSTALL_PREFIX="$LIBS" -DCMAKE_BUILD_TYPE=Release \
-DDOCTEST_WITH_TESTS=OFF -DDOCTEST_WITH_MAIN_IN_STATIC_LIB=ON
-DDOCTEST_WITH_TESTS=OFF -DDOCTEST_WITH_MAIN_IN_STATIC_LIB=ON -DDOCTEST_USE_STD_HEADERS=OFF
echo -e "${BW}${target}: Building ${DOCTEST}${NC}"
cmake --build "$BUILD"
#echo -e "${BW}${target}: Testing ${DOCTEST}${NC}"
Expand Down
4 changes: 2 additions & 2 deletions include/utap/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class expression_t
* (s.f).get_symbol() returns 's'
* (i<1?j:k).get_symbol() returns 'j'
*/
symbol_t get_symbol();
const symbol_t& get_symbol();

/**
* Returns the set of symbols this expression might resolve
Expand All @@ -182,7 +182,7 @@ class expression_t

/** Returns the symbol this expression evaluates to. Notice
that not all expression evaluate to a symbol. */
const symbol_t get_symbol() const;
const symbol_t& get_symbol() const;

/** Returns true if this expression is a reference to a
symbol in the given set. */
Expand Down
4 changes: 2 additions & 2 deletions src/ExpressionBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ void ExpressionBuilder::expr_call_end(uint32_t n)
{
expression_t e;
type_t type;
instance_t* instance;
const instance_t* instance;

/* n+1'th element from the top is the identifier.
*/
Expand Down Expand Up @@ -352,7 +352,7 @@ void ExpressionBuilder::expr_call_end(uint32_t n)
if (expr.size() - 1 != id.get_type().size()) {
handle_error(TypeException{"$Wrong_number_of_arguments"});
}
instance = static_cast<instance_t*>(id.get_symbol().get_data());
instance = static_cast<const instance_t*>(id.get_symbol().get_data());

/* Process set lookups are represented as expressions indexing
* into an array. To satisfy the type checker, we create a
Expand Down
8 changes: 5 additions & 3 deletions src/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,9 @@ bool expression_t::equal(const expression_t& e) const
case of inline if, the symbol referenced by the 'true' part is
returned.
*/
symbol_t expression_t::get_symbol() { return ((const expression_t*)this)->get_symbol(); }
const symbol_t& expression_t::get_symbol() { return ((const expression_t*)this)->get_symbol(); }

const symbol_t expression_t::get_symbol() const
const symbol_t& expression_t::get_symbol() const
{
assert(data);

Expand Down Expand Up @@ -674,7 +674,9 @@ const symbol_t expression_t::get_symbol() const

case SCENARIO: return get(0).get_symbol();

default: return symbol_t();
default:
assert(false);
// return symbol_t();
}
}

Expand Down

0 comments on commit 57e50fd

Please sign in to comment.