-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Open
Labels
chronoIssues related to std::chronoIssues related to std::chronoclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"compiler-rt:ubsanUndefined behavior sanitizerUndefined behavior sanitizerlibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.undefined behaviour
Description
https://godbolt.org/z/r8Yd7nhzc
Not sure standard requires this behavior or not, but it is undefined behavior in IMPLICI T conversion, in naive code, which is expected to be working. Huge disappointment in std::chrono
#include <chrono>
#include <iostream>
int main() {
std::chrono::nanoseconds ns = std::chrono::milliseconds::max();
std::cout << ns.count() << "|" << ns.max().count();
}
Output:
/opt/compiler-explorer/gcc-13.1.0/include/c++/13.1.0/bits/chrono.h:225:38: runtime error: signed integer overflow: 9223372036854775807 * 1000000 cannot be represented in type 'long int'
-1000000|9223372036854775807
Expected: max count of nanoseconds
Additionaly: clang (when writed as one line) ignores undefined behavior while constant folding
Metadata
Metadata
Assignees
Labels
chronoIssues related to std::chronoIssues related to std::chronoclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"compiler-rt:ubsanUndefined behavior sanitizerUndefined behavior sanitizerlibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.undefined behaviour