-
Notifications
You must be signed in to change notification settings - Fork 805
[diff.mods.to.headers] Cover type-generic macro suppression #8665
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
base: main
Are you sure you want to change the base?
[diff.mods.to.headers] Cover type-generic macro suppression #8665
Conversation
| standard library. Whereas the \libheader{tgmath.h} macros can be suppressed in | ||
| C by, for example, using parentheses around the macro name, the \Cpp{} overload | ||
| sets cannot be bypassed in this manner; casts may be used instead. |
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 seems tutorial-like to be honest. The wording is clear that the tgmath.h macros don't exist in C++, and that's all that really needs to be said about compatibility differences.
Even if we want to have this new sentence, it seems like something that goes into a \begin{note} context.
I'm also not sure what you mean by "casts may be used instead". Are you casting the function itself to double(&)(double)? That isn't valid because of addressability restrictions. You could cast all the function arguments like sqrt((double)x), but that's possible in both languages, so it doesn't seem like it needs to be called out in [diff].
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 agree with the statement about casts; @hubert-reinterpretcast , please tell us what you mean by those "casts".
I do want to point out that Annex C is tutorial-like in nature (nothing new in that Annex, hopefully), so I'm not objecting to adding a clarifying sentence. However, I wonder whether an actual code example would convey the consequences more clearly.
#include <tgmath.h>
double x = (sqrt)(2.0f); // calls sqrt(double) in C, but sqrt(float) in C++
Maybe just striking "casts may be used instead" is a way forward?
|
@eisenwave , we didn't get a priority label here :-) |
|
How come all major compilers accept the following: #include <cmath>
void f() {
(std::sqrt)(0.0);
}Wouldn't this need to be an error because |
|
Hold on, I do think there is actually an incompatibility in some sense. I believe the wording currently mandates that if you include This means that the type of the expression #include <math.h>
#include <type_traits>
// passes, but doesn't match the C behavior:
static_assert(std::is_same_v<decltype(sqrt(0.f)), float>);
// same:
static_assert(std::is_same_v<decltype((sqrt)(0.f)), float>);So P2 because there is a missing incompatibility from [diff]. |
No description provided.