Skip to content

Commit 37c7feb

Browse files
committed
fixed -Wlifetime-safety-intra-tu-suggestions Clang warnings
1 parent 4bd5e10 commit 37c7feb

3 files changed

Lines changed: 16 additions & 12 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,11 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
7373
add_compile_options_safe(-Wno-thread-safety-negative)
7474
add_compile_options_safe(-Wno-thread-safety-beta)
7575

76-
# TODO: enable
77-
add_compile_options_safe(-Wno-lifetime-safety-intra-tu-suggestions)
76+
# we do not add the annotation until C++20
77+
# the warnings were introduced with Clang 23
78+
if(CMAKE_CXX_STANDARD LESS 20)
79+
add_compile_options_safe(-Wno-lifetime-safety-intra-tu-suggestions)
80+
endif()
7881
add_compile_options_safe(-Wno-lifetime-safety-intra-tu-constructor-suggestions)
7982
add_compile_options_safe(-Wno-lifetime-safety-cross-tu-constructor-suggestions)
8083

@@ -88,6 +91,7 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
8891
# we are not interested in these
8992
set_source_files_properties(test.cpp PROPERTIES COMPILE_FLAGS "-Wno-multichar -Wno-four-char-constants")
9093

94+
# TODO: check for proper AppleClang version
9195
if (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 14 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14)
9296
# TODO: verify this regression still exists in clang-15
9397
if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")

simplecpp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,7 @@ namespace simplecpp {
16891689
}
16901690

16911691
/** how has this macro been used so far */
1692-
const std::list<Location> &usage() const {
1692+
const std::list<Location> &usage() const SIMPLECPP_LIFETIMEBOUND {
16931693
return usageList;
16941694
}
16951695

@@ -1884,7 +1884,7 @@ namespace simplecpp {
18841884

18851885
const Token *appendTokens(TokenList &tokens,
18861886
const Location &rawloc,
1887-
const Token * const lpar,
1887+
const Token * const lpar SIMPLECPP_LIFETIMEBOUND,
18881888
const MacroMap &macros,
18891889
const std::set<TokenString> &expandedmacros,
18901890
const std::vector<const Token*> &parametertokens) const {
@@ -3011,7 +3011,7 @@ static long long evaluate(simplecpp::TokenList &expr, const simplecpp::DUI &dui,
30113011
return expr.cfront() && expr.cfront() == expr.cback() && expr.cfront()->number ? stringToLL(expr.cfront()->str()) : 0LL;
30123012
}
30133013

3014-
static const simplecpp::Token *gotoNextLine(const simplecpp::Token *tok)
3014+
static const simplecpp::Token *gotoNextLine(const simplecpp::Token *tok SIMPLECPP_LIFETIMEBOUND)
30153015
{
30163016
const unsigned int line = tok->location.line;
30173017
const unsigned int file = tok->location.fileIndex;

simplecpp.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ namespace simplecpp {
172172

173173
Token &operator=(const Token &tok) = delete;
174174

175-
const TokenString& str() const {
175+
const TokenString& str() const SIMPLECPP_LIFETIMEBOUND {
176176
return string;
177177
}
178178
void setstr(const std::string &s) {
@@ -493,22 +493,22 @@ namespace simplecpp {
493493
size_type size() const {
494494
return mData.size();
495495
}
496-
iterator begin() {
496+
iterator begin() SIMPLECPP_LIFETIMEBOUND {
497497
return mData.begin();
498498
}
499-
iterator end() {
499+
iterator end() SIMPLECPP_LIFETIMEBOUND {
500500
return mData.end();
501501
}
502-
const_iterator begin() const {
502+
const_iterator begin() const SIMPLECPP_LIFETIMEBOUND {
503503
return mData.begin();
504504
}
505-
const_iterator end() const {
505+
const_iterator end() const SIMPLECPP_LIFETIMEBOUND {
506506
return mData.end();
507507
}
508-
const_iterator cbegin() const {
508+
const_iterator cbegin() const SIMPLECPP_LIFETIMEBOUND {
509509
return mData.cbegin();
510510
}
511-
const_iterator cend() const {
511+
const_iterator cend() const SIMPLECPP_LIFETIMEBOUND {
512512
return mData.cend();
513513
}
514514

0 commit comments

Comments
 (0)