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

fix(to_cpp1): improve recognition of dependent types and deducible parameters #533

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

Conversation

JohelEGP
Copy link
Contributor

@JohelEGP JohelEGP commented Jul 1, 2023

Resolves #534. Resolves #595.
Resolves #628 (as a discussion, this needs to be manually closed).
Adds what's needed to diagnose #572.

@JohelEGP

This comment was marked as resolved.

@JohelEGP JohelEGP changed the title fix(cpp1): emit typename in dependent type-only contexts fix(cpp1): emit typename/template in unambiguous dependent contexts Jul 4, 2023
source/cppfront.cpp Outdated Show resolved Hide resolved
@JohelEGP JohelEGP changed the title fix(cpp1): emit typename/template in unambiguous dependent contexts fix(cpp1): improve recognition of dependent and deducible parameters Jul 6, 2023
@JohelEGP JohelEGP changed the title fix(cpp1): improve recognition of dependent and deducible parameters fix(cpp1): improve recognition of dependent types and deducible parameters Jul 6, 2023
source/cppfront.cpp Outdated Show resolved Hide resolved
source/cppfront.cpp Outdated Show resolved Hide resolved
@JohelEGP JohelEGP changed the title fix(cpp1): improve recognition of dependent types and deducible parameters fix(to_cpp1): improve recognition of dependent types and deducible parameters Nov 9, 2023
@JohelEGP
Copy link
Contributor Author

JohelEGP commented Dec 12, 2023

Patch for merging with #596:

diff --git a/source/to_cpp1.h b/source/to_cpp1.h
index 5286c3ee..01cb93b5 100644
--- a/source/to_cpp1.h
+++ b/source/to_cpp1.h
@@ -2234,6 +2234,12 @@ public:
         {
             return self->is_dependent(*expr.result_type);
         }
+
+        auto operator()(requires_expression_node const&) const
+            -> bool
+        {
+            return false;
+        }
     };
 
     auto is_dependent(

@JohelEGP
Copy link
Contributor Author

JohelEGP commented Sep 24, 2024

In type-only contexts, we can also allow a space between the identifier and the template-argument-list opener.

assert <_>(); // OK, `<` never an operator.
_ = std::vector <int>(); // Error, `<` interpreted as an operator.
_ = :std::vector <int> = (); // Error, same as above, but as a type-only context, we know it's not an operator.

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

hsutter commented Oct 31, 2024

Hi! Sorry it took me so long to get to this one... but this looks like it might still be current. It's a bigger diff, but part of it is the stack_ helpers that got merged from I think another one of your PRs.

Is this up to date, and would you like me to review it?

@hsutter hsutter added the question - further information requested Further information is requested label Oct 31, 2024
@JohelEGP
Copy link
Contributor Author

Yes, and yes, please do.

^
pure2-bugfix-for-dependent-types-recursion.cpp2:3:13: error: unknown type name 'a'
using b = a;
^
Copy link
Owner

Choose a reason for hiding this comment

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

Is it intended that these test cases fail?

  • pure2-bugfix-for-dependent-types-recursion
  • pure2-bugfix-for-dependent-types

For some reason the latter works on GCC 14?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pure2-bugfix-for-dependent-types-recursion should fail.
It tests that the algorithm detects recursio,
and returns false (i.e., "not a dependent type"),
to let the Cpp1 compiler give its diagnostic.

pure2-bugfix-for-dependent-types shouldn't fail on a modern compiler.
I see some are failing because they don't yet support optional typename.

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

Successfully merging this pull request may close these issues.

[BUG] Template deduction fails [BUG] Recognize non-deducible parameter
2 participants