[Bug c++/113852] -Wsign-compare doesn't warn on unsigned result types
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113852 --- Comment #7 from Zachary L --- (In reply to Richard Biener from comment #6) > Well, given athat a1 * a2 is carried out in 'int' you are invoking undefined > behavior if it overflows. GCC assumes that doesn't happen so it's correct > to elide the diagnostic. Unless you make overflow well-defined with -fwrapv. > > I think that errors on the right side for the purpose of -Wsign-compare. Removing a diagnostic because the program could be ill-formed seems backwards to me, especially since it seems like there's already logic in performing this diagnostic. Perhaps I've misunderstood the situation?
[Bug c++/113852] -Wsign-compare doesn't warn on unsigned result types
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113852 --- Comment #1 from Zachary L --- Sorry, that should say "If *both* a1 or a2 are constexpr, the warning will occur."
[Bug c++/113852] New: -Wsign-compare doesn't warn on unsigned result types
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113852 Bug ID: 113852 Summary: -Wsign-compare doesn't warn on unsigned result types Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: admin at computerquip dot com Target Milestone: --- I haven't quite figured out the pattern here so the title may not be great. Some code may help explain better: https://godbolt.org/z/d8cqd1WqP ``` #include #include #include int main() { uint16_t a1 = std::numeric_limits::max(); uint16_t a2 = std::numeric_limits::max(); /* a1 * a2 should be 4294836225 in math terms */ uint64_t a3 = 4294836225; /* * The result of (a1 * a2) is of type int and the result is negative. * (a1 * a2) ends up as some bogus high number because the common * type here ends up as uint64_t and sign-extension occurs. */ if ((a1 * a2) > a3) { std::cout << "this will print\n"; } } ``` Some observations I've noticed: * If either a1 or a2 are constexpr, the warning will occur. * This used to warn up until 8.1. * Clang also doesn't warn here but MSVC will with /W3 or higher. * This seems like a slight variation of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101645
[Bug libstdc++/111145] New: istream::operator>>(streambuf*) does not set gcount
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=45 Bug ID: 45 Summary: istream::operator>>(streambuf*) does not set gcount Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: admin at computerquip dot com Target Milestone: --- Example code: https://godbolt.org/z/cW9Pe1c85 ``` #include #include int main() { std::ostringstream oss; std::istringstream iss("test"); iss >> oss.rdbuf(); std::cout << "gcount is " << iss.gcount() << "\n"; } ``` Here I'm expecting `iss.gcount()` to return 4 as `iss >> oss.rdbuf();`, as far as I can tell, fits under the conditions that should set the value accessed by gcount(). As per the godbolt link, it instead returns 0.