Skip to content

[clang] missed integer overflow warning with CXXTemporary values #63629

@lnihlen

Description

@lnihlen

compiler explorer link: https://godbolt.org/z/Wd318Mdrx

typedef long long int64_t;

template<typename T>
class u_ptr {
  T *ptr;
public:
  u_ptr(const u_ptr&) = delete;
  u_ptr &operator=(const u_ptr&) = delete;
  u_ptr(u_ptr &&other) : ptr(other.ptr) { other.ptr = 0; }
  u_ptr(T *ptr) : ptr(ptr) { }
  ~u_ptr() { delete ptr; }
};

u_ptr<bool> Wrap(int64_t x) {
    return nullptr;
}

int64_t Pass(int64_t x) { return x; }

int main(int argc, char* argv[]) {
    // This trips -Winteger-overflow:
    int64_t x = Pass(30 * 24 * 60 * 59 * 1000);
    
    // This doesn't trip -Winteger-overflow.
    auto r = Wrap(Pass(30 * 24 * 60 * 59 * 1000));
    
    return 0;
}

Patch coming shortly.

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