-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor: fix msvc warning "not all control paths return a value" #5650
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
79b6525
Minor: fix msvc warning "not all control paths return a value"
StefanVK 9d2d226
Merge branch 'danmar:main' into fix_noreturn_msvc_warning
StefanVK 7bcdf4a
Minor: fix msvc warning "not all control paths return a value"
StefanVK b3e07d4
Fix formatting / run uncrustify
StefanVK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer if we keep the
#else
at the end.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but how do we handle the case of a compiler which supports
__has_cpp_attribute
but for which__has_cpp_attribute (noreturn)
is false? I don't know that such a case exists but I wouldn't want to assume it does not.The
__has_pp_attribute(noreturn)
check has to be guarded by adefined __has_cpp_attribute
check if you don't want to trip up compilers which don't support __has_cpp_attribute.https://godbolt.org/z/je4jM6W3h
That's why I think we either have to duplicate code in the
#else
forif __has_cpp_attribute (noreturn)
or go the!defined(NORETURN)
route.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is indeed in contradiction with my other comment. I realized it myself shortly after I wrote it.
But we could move the check for
__has_cpp_attribute
out and set a different define we check in addition. That would avoid potential duplicate code if we need to check a feature in another place.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean like
If that's what you meant, I fail to see a benefit but it would work fine as well. If you feel strongly about it, I'll modify it like that.
If you meant something else, could you please clarify? I'm not sure I got your idea. Just setting a different '#define' for whether
__has_cpp_attribute
is supported would not help with the syntax error in__has_cpp_attribute (noreturn)
when it's not supported.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right. I forgot about this annoying quirk. As I mentioned my experiences with post-c+11 code bases are few.
I don't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the kind of solution I was looking for was something we already use in
sourcelocation.h
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm that's not standard compliant code, is it? I'd be careful defining symbols starting with "__".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it has nothing to do with the standard but
__
macros are reserved and should not be specified by user code. It did not cause any Clang (I think-Wreserved-macro-identifier
covers this) or clang-tidy warnings, so I guess it is fine. Maybe the#ifndef
instead of just defining it unconditionally.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I admit that the following is only language lawyer nitpicking and I think we'll be fine in practice the way cppcheck is now using it. But if you feel like reading an argument partly against it anyway, here it goes:
Yes, I think you're not getting the reserved identifier warning because you're testing with a clang version that supports
__has_builtin
and you are not defining the identifier because it is#ifndef
'ed out. Clang does warn about reserved-macro-identifier when such a define takes place: https://godbolt.org/z/jhEK5vT8EA program which
#define
s an identifier with__
breaks a shall rule with no diagnostic required (https://eel.is/c++draft/lex.name#3 https://eel.is/c++draft/intro.compliance#general-2.2). TIL there's even a clause specifically forbidding__has_cpp_attribute
in anything but a preprocessor check (https://eel.is/c++draft/cpp.cond#7).Standard library implementations also do work with those identifiers but I did not find a case that you'd be breaking by defining them like you're doing.
I actually came across a case just like ours on isocpp.org. Still to my understanding it's not in line with the letter of the standard.