Skip to content

Commit ef20644

Browse files
JOE1994Sirraide
andauthored
[clang] Warn const integer-overflow of member in temporary struct bound to rvalue reference (#117225)
Fixes #46755 --------- Co-authored-by: Sirraide <[email protected]>
1 parent 1d46020 commit ef20644

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,9 @@ Improvements to Clang's diagnostics
580580

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

583+
- For an rvalue reference bound to a temporary struct with an integer member, Clang will detect constant integer overflow
584+
in the initializer for the integer member (#GH46755).
585+
583586
Improvements to Clang's time-trace
584587
----------------------------------
585588

clang/lib/Sema/SemaChecking.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12048,7 +12048,8 @@ void Sema::CheckForIntOverflow (const Expr *E) {
1204812048
New && New->isArray()) {
1204912049
if (auto ArraySize = New->getArraySize())
1205012050
Exprs.push_back(*ArraySize);
12051-
}
12051+
} else if (const auto *MTE = dyn_cast<MaterializeTemporaryExpr>(OriginalE))
12052+
Exprs.push_back(MTE->getSubExpr());
1205212053
} while (!Exprs.empty());
1205312054
}
1205412055

clang/test/SemaCXX/integer-overflow.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,10 @@ int m() {
246246
return 0;
247247
}
248248
}
249+
250+
namespace GH46755 {
251+
void f() {
252+
struct { int v; } &&r = {512 * 1024 * 1024 * 1024}; // expected-warning {{overflow in expression; result is 0 with type 'int'}}
253+
}
254+
}
249255
#endif

0 commit comments

Comments
 (0)