Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Inconsistent shift-overflow warnings in C++20 #52873

Closed
Assignees
xgupta
Labels
c++20clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer
@manxorist

Description

@manxorist

Consider the following code:

intfoo4s() {return (0x7000'0000) <<4;}unsignedintfoo4u() {return (0x7000'0000u) <<4;}intfoo1s() {return (0x7000'0000) <<1;}unsignedintfoo1u() {return (0x7000'0000u) <<1;}

which when compiled with-std=c++20 -Wall -Wextra -Wpedantic results in:

<source>:2:26: warning: signed shift result (0x700000000) requires 36 bits to represent, but 'int' only has 32 bits [-Wshift-overflow]    return (0x7000'0000) << 4;           ~~~~~~~~~~~~~ ^  ~1 warning generated.

In C++20, the semantics are just as well defined for the signed case as they are for the unsigned case, thus generating a warning when shifting bits outside of a signed target type and not when shifting outside of a unsigned target type seems inconsistent to me.

GCC does not warn in this case in C++20 mode. Seehttps://godbolt.org/z/9rbafz3h3.

This came up when discussing a similar (but not identical) issue in GCC. Seehttps://gcc.gnu.org/bugzilla/show_bug.cgi?id=103826

Metadata

Metadata

Assignees

Labels

c++20clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp