Skip to content

Commit 0db6694

Browse files
committed
fixed -Wlifetime-safety-intra-tu-suggestions Clang warnings
1 parent 6582125 commit 0db6694

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
@@ -77,8 +77,11 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
7777
add_compile_options_safe(-Wno-thread-safety-negative)
7878
add_compile_options_safe(-Wno-thread-safety-beta)
7979

80-
# TODO: enable
81-
add_compile_options_safe(-Wno-lifetime-safety-intra-tu-suggestions)
80+
# we do not add the annotation until C++20
81+
# the warnings were introduced with Clang 23
82+
if(CMAKE_CXX_STANDARD LESS 20)
83+
add_compile_options_safe(-Wno-lifetime-safety-intra-tu-suggestions)
84+
endif()
8285
add_compile_options_safe(-Wno-lifetime-safety-intra-tu-constructor-suggestions)
8386
add_compile_options_safe(-Wno-lifetime-safety-cross-tu-constructor-suggestions)
8487

@@ -92,6 +95,7 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
9295
# we are not interested in these
9396
set_source_files_properties(test.cpp PROPERTIES COMPILE_FLAGS "-Wno-multichar -Wno-four-char-constants")
9497

98+
# TODO: check for proper AppleClang version
9599
if (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 14 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14)
96100
# TODO: verify this regression still exists in clang-15
97101
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
@@ -181,7 +181,7 @@ namespace simplecpp {
181181

182182
Token &operator=(const Token &tok) = delete;
183183

184-
const TokenString& str() const {
184+
const TokenString& str() const SIMPLECPP_LIFETIMEBOUND {
185185
return string;
186186
}
187187
void setstr(const std::string &s) {
@@ -502,22 +502,22 @@ namespace simplecpp {
502502
size_type size() const {
503503
return mData.size();
504504
}
505-
iterator begin() {
505+
iterator begin() SIMPLECPP_LIFETIMEBOUND {
506506
return mData.begin();
507507
}
508-
iterator end() {
508+
iterator end() SIMPLECPP_LIFETIMEBOUND {
509509
return mData.end();
510510
}
511-
const_iterator begin() const {
511+
const_iterator begin() const SIMPLECPP_LIFETIMEBOUND {
512512
return mData.begin();
513513
}
514-
const_iterator end() const {
514+
const_iterator end() const SIMPLECPP_LIFETIMEBOUND {
515515
return mData.end();
516516
}
517-
const_iterator cbegin() const {
517+
const_iterator cbegin() const SIMPLECPP_LIFETIMEBOUND {
518518
return mData.cbegin();
519519
}
520-
const_iterator cend() const {
520+
const_iterator cend() const SIMPLECPP_LIFETIMEBOUND {
521521
return mData.cend();
522522
}
523523

0 commit comments

Comments
 (0)