llvm-project/clang/test/Sema/integer-overflow.cpp
Shafik Yaghmour 9332ddfba6 [Clang] Extend the number of case Sema::CheckForIntOverflow covers
Currently Sema::CheckForIntOverflow misses several case that other compilers
diagnose for overflow in integral constant expressions. This includes the
arguments of a CXXConstructExpr as well as the expressions used in an
ArraySubscriptExpr, CXXNewExpr and CompoundLiteralExpr.

This fixes https://github.com/llvm/llvm-project/issues/58944

Differential Revision: https://reviews.llvm.org/D137897
2022-11-15 12:07:03 -08:00

19 lines
638 B
C++

// RUN: %clang_cc1 %s -Wno-unused-value -verify -fsyntax-only
namespace GH58944 {
struct A {
A(unsigned long) ;
};
A a(1024 * 1024 * 1024 * 1024 * 1024ull); // expected-warning {{overflow in expression; result is 0 with type 'int'}}
void f() {
new int[1024 * 1024 * 1024 * 1024 * 1024ull]; // expected-warning {{overflow in expression; result is 0 with type 'int'}}
int arr[]{1,2,3};
arr[1024 * 1024 * 1024 * 1024 * 1024ull]; // expected-warning {{overflow in expression; result is 0 with type 'int'}}
(int){1024 * 1024 * 1024 * 1024 * 1024}; // expected-warning {{overflow in expression; result is 0 with type 'int'}}
}
}