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 error reported by Clang #1702

Merged
merged 3 commits into from
Feb 2, 2018
Merged

Conversation

ts826848
Copy link
Contributor

Error message:

./numerics/fixed_arrays_body.hpp:122:46: error: use 'template' keyword to treat 'Row' as a dependent
      template name
typename FixedMatrix<Scalar, rows, columns>::Row<r>
                                             ^
                                             template

Error message:

    ./numerics/fixed_arrays_body.hpp:122:46: error: use 'template' keyword to treat 'Row' as a dependent
          template name
    typename FixedMatrix<Scalar, rows, columns>::Row<r>
                                                 ^
                                                 template
@pleroy
Copy link
Member

pleroy commented Jan 30, 2018

Can one of the admins verify this patch?

@eggrobin
Copy link
Member

retest this please

@eggrobin
Copy link
Member

@aw1621107, it seems that this confuses MSVC:
numerics/fixed_arrays_body.hpp(125): error C2244: 'principia::numerics::internal_fixed_arrays::FixedMatrix<Scalar,rows,columns>::row': unable to match function definition to an existing declaration.

Maybe it is one of these cases where we need a TEMPLATE macro that expands to template for clang only? We used to have a TYPENAME like this...

@eggrobin
Copy link
Member

An alternative would be to use a trailing return type -> Row<r>, but this would be inconsistent with our surrounding style. @pleroy, what do you think?

@pleroy
Copy link
Member

pleroy commented Jan 31, 2018

Here is the commit that removed TEMPLATE, let's add it back.

Sorry, something went wrong.

@ts826848
Copy link
Contributor Author

Should I close this PR then?

Sorry, something went wrong.

@eggrobin
Copy link
Member

No, add TEMPLATE back to macros.hpp and use it here; we still want things to build on Macintosh and Linux.

Sorry, something went wrong.

@eggrobin
Copy link
Member

eggrobin commented Feb 1, 2018

Another alternative is to change the declaration to typename FixedMatrix::template Row<r>, which should deconfuse MSVC; see https://godbolt.org/g/awXGmV.

Sorry, something went wrong.

@pleroy
Copy link
Member

pleroy commented Feb 1, 2018

I interpret the last section of this article on cppreference as saying that (1) template is required on the definition and (2) template is permitted on the declaration, where it is unnecessary. I vote for @eggrobin's fix.

The standard requires `template` for dependent template names used in
definitions and permits it in definitions. Using `template` in the
definition but not the declaration seems to confuse MSVC, though:

    numerics/fixed_arrays_body.hpp(125): error C2244: 'principia::numerics::internal_fixed_arrays::FixedMatrix<Scalar,rows,columns>::row': unable to match function definition to an existing declaration.
@ts826848
Copy link
Contributor Author

ts826848 commented Feb 1, 2018

Alright, I think I implemented @eggrobin's change?

@@ -72,7 +72,7 @@ class FixedMatrix final {
};

template<int r>
Row<r> row() const;
typename FixedMatrix<Scalar, rows, columns>::template Row<r> row() const;
Copy link
Member

Choose a reason for hiding this comment

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

You don't need the parameters on FixedMatrix: within the definition, FixedMatrix without parameters refers to the class being defined. The following should be enough:

template<int r>
typename FixedMatrix::template Row<r> row() const;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, didn't know that. Fixed!

@pleroy
Copy link
Member

pleroy commented Feb 2, 2018

As usual, thanks for the contribution.

@pleroy pleroy added the LGTM label Feb 2, 2018
@pleroy pleroy merged commit 8d3d5d8 into mockingbirdnest:master Feb 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants