Skip to content
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

feat: accept function type argument #923

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

JohelEGP
Copy link
Contributor

@JohelEGP JohelEGP commented Jan 8, 2024

Resolves #628 (comment).

Testing summary:

100% tests passed, 0 tests failed out of 906

Total Test time (real) =  47.97 sec

Acknowledgements:

source/parse.h Outdated Show resolved Hide resolved
@hsutter
Copy link
Owner

hsutter commented Jan 9, 2024

From #628:

But what about offsetof (https://en.cppreference.com/w/cpp/types/offsetof)?
And more generally the compiler built-ins?
Unfortunately, generally supporting function type arguments seems like it would require typename.

Can you elaborate with examples where this is used? I'm not seeing the use cases in the PR code shown so far, unless the answer to my first question about sizeof(type ...) is that the type alters the meaning somehow.

source/parse.h Outdated Show resolved Hide resolved
_ = typeid(int);
_ = offsetof(t, a);
_ = :<T> (_: T) _ = sizeof(T::value);(std::true_type());
_ = :<T> (_: T) _ = sizeof(type T::value_type);(std::true_type());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there intended to be a difference between lines 7 and 8? Or is the type intended to be optional?

If there's no difference, can you show a case where it's required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second one needs the disambiguating type.
See https://cpp1.godbolt.org/z/PY53n6Kvf (generated from https://cpp2.godbolt.org/z/KK15vf6Y5):

  • Clang: error: dependent-name 'T::value_type' is parsed as a non-type, but instantiation yields a type.
  • GCC: error: missing 'typename' prior to dependent type name 'integral_constant<bool, true>::value_type'.
  • MSVC accepts.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'oh, now I see it. I missed the _type suffix that changed the meaning, sorry.

@@ -5,7 +5,7 @@ testing_enabled: bool = false;

outer: @print type = {

object_alias: <T> T requires true == 42;
object_alias: <T> T requires true == sizeof(type T::value_type);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just to exercise type for this pretty-print self-test, or is type now intended to be required here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The former.
This change is intended to exercise the type keyword in the pretty-print.

@@ -5800,9 +5845,6 @@ class parser
//G postfix-expression
//G prefix-operator prefix-expression
//GTODO await-expression
//GTODO 'sizeof' '(' type-id ')'
//GTODO 'sizeof' '...' ( identifier ')'
//GTODO 'alignof' '(' type-id ')'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, these should go anyway as they already work without a special grammar. And throws-expression too, since throw(...) works (and I'm using that in reflect.h2's report_violation function).

@JohelEGP

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants