Skip to content

Commit 08e1a33

Browse files
committed
[clang] Warn const integer-overflow of member in temporary struct bound to rvalue reference
Fixes #46755
1 parent 8663b87 commit 08e1a33

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
@@ -578,6 +578,9 @@ Improvements to Clang's diagnostics
578578

579579
- Clang now omits shadowing warnings for parameter names in explicit object member functions (#GH95707).
580580

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

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)