This bugzilla service is closed. All entries have been migrated to
Bug 1278 - Abused C operator precedence in use of ternary within conditional.
Summary: Abused C operator precedence in use of ternary within conditional.
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - matrix products (show other bugs)
Version: unspecified
Hardware: All All
: Normal Compilation Problem
Assignee: Nobody
Depends on:
Reported: 2016-08-20 02:01 UTC by Glenn
Modified: 2019-12-04 16:07 UTC (History)
2 users (show)


Description Glenn 2016-08-20 02:01:52 UTC
A static code analysis tool flagged this code in GeneralMatrixVector.h as problematic.

Here is the code in question:
  const Index offset1 = (FirstAligned && alignmentStep==1?3:1);
  const Index offset3 = (FirstAligned && alignmentStep==1?1:3);

What is the intent here? I believe this is parsed in the following way due to C operator precedence (
  const Index offset1 = (FirstAligned && alignmentStep==1)?3:1;
  const Index offset3 = (FirstAligned && alignmentStep==1)?1:3;

But that's not entirely clear.  The current use of () strikes me as actually misleading, implying the following:
  const Index offset1 = (FirstAligned && (alignmentStep==1?3:1));
  const Index offset3 = (FirstAligned && (alignmentStep==1?1:3));

While the code in question may be technically correct, it can be made much easier to read and understand.
Comment 1 Gael Guennebaud 2016-08-22 13:02:02 UTC
Comment 2 Nobody 2019-12-04 16:07:47 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance:

Note You need to log in before you can comment on or make changes to this bug.