Skip to content

Commit

Permalink
[clang] Warn const integer-overflow of member in temporary struct bou…
Browse files Browse the repository at this point in the history
…nd to rvalue reference (#117225)

Fixes #46755

---------

Co-authored-by: Sirraide <[email protected]>
  • Loading branch information
JOE1994 and Sirraide authored Nov 22, 2024
1 parent 1d46020 commit ef20644
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,9 @@ Improvements to Clang's diagnostics

- Improved error recovery for function call arguments with trailing commas (#GH100921).

- For an rvalue reference bound to a temporary struct with an integer member, Clang will detect constant integer overflow
in the initializer for the integer member (#GH46755).

Improvements to Clang's time-trace
----------------------------------

Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12048,7 +12048,8 @@ void Sema::CheckForIntOverflow (const Expr *E) {
New && New->isArray()) {
if (auto ArraySize = New->getArraySize())
Exprs.push_back(*ArraySize);
}
} else if (const auto *MTE = dyn_cast<MaterializeTemporaryExpr>(OriginalE))
Exprs.push_back(MTE->getSubExpr());
} while (!Exprs.empty());
}

Expand Down
6 changes: 6 additions & 0 deletions clang/test/SemaCXX/integer-overflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,10 @@ int m() {
return 0;
}
}

namespace GH46755 {
void f() {
struct { int v; } &&r = {512 * 1024 * 1024 * 1024}; // expected-warning {{overflow in expression; result is 0 with type 'int'}}
}
}
#endif

0 comments on commit ef20644

Please sign in to comment.