Skip to content

No signed integer overflow warning reported in the call to constructor #58944

Closed
@Fedr

Description

@Fedr

In the following program there are two similar signed integer overflows:

#include <cstdint>

void func(uint64_t) {}

struct A { 
    A(uint64_t){} 
};

int main() {
    func(1024 * 1024 * 1024 * 1024 * 1024ull); // warning, ok
    A a(1024 * 1024 * 1024 * 1024 * 1024ull); // no warning in Clang!
}

The one in calling func is detected by Clang.
But the other one in calling A::A does not, even with -Wall -Wextra flags. At the same time both GCC and MSVC reports the warning here as well. Online demo: https://gcc.godbolt.org/z/6vGT33q1W

Related discussion: https://stackoverflow.com/q/73962573/7325599

Metadata

Metadata

Assignees

Labels

clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second party

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions