Skip to content

Diagnostics for -Wunsafe-buffer-usage won't fire unless enabled at *end* of file #79379

Open
@mmdriley

Description

@mmdriley

Like with other diagnostics it's possible to control -Wunsafe-buffer-usage with #pragma clang diagnostic within a source file. However, there's a weird nonlocal effect: for any instances of the warning to fire, it seems the warning must be enabled at the point of occurrence and at the end of the file.

This isn't true for other warnings like -Wsign-compare.

You can see an example here: https://godbolt.org/z/4eGc5hdzd

Initially there are no -Wunsafe-buffer-usage warnings. But if you uncomment the last line of the input (#pragma clang diagnostic warning "-Wunsafe-buffer-usage") then warnings that appear earlier in the file will show up.

Metadata

Metadata

Assignees

Labels

clang: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