1
votes

UPDATED: Added complete example and compiler information

I have Eclipse 2019-03 (4.11.0) with CDT 9.7.0.20190309 and the build-in compiler reports false positive errors while using std::index_sequence in C++17:

#include <gtest/gtest.h>
#include <utility>
#include <array>

class Sample {
public:
    template<std::size_t N >
    std::size_t get_percentage( void ) {
        return N;
    }

    template<std::size_t... Is>
    inline std::array<std::size_t, sizeof...(Is)> calculate_percentages( std::index_sequence<Is...> ) noexcept {
        return { this->get_percentage<Is>()... };
    }
    template<std::size_t N>
    inline std::array<std::size_t, N> get_percentages( void ) noexcept {
        return this->calculate_percentages( std::make_index_sequence<N>() );
    /*           ^^^^^^^^^^^^^^^^^^^^^ : Invalid arguments ' Candidates are: std::array calculate_percentages(std::integer_sequence) ' */
    }
};

TEST( IntegerSequence, InvalidArgumentsError ) {
    Sample test;
    std::array<std::size_t, 5> data = test.get_percentages<5>();
    for( int i = 0; i < 5; i++ ) {
        std::cout << data[i] << std::endl;
    }
}

int main( int argc, char ** argv ) {
    testing::InitGoogleTest( &argc, argv );
    return RUN_ALL_TESTS();
}

But the normal compilation succeeds without any problem.

My CDT GCC Built-in Compiler Settings in Project Properties -> C/C++ General -> Preprocessor Include Paths, Macros etc. -> Providers is as follows:

${COMMAND} ${FLAGS} -E -P -v -dD -std=c++17 "${INPUTS}"

The same applies for CDT Cross GCC Built-in Compiler Settings.

Rebuilding the index does not helped in there.

The GCC version I am using:

gcc (Ubuntu 8.3.0-6ubuntu1) 8.3.0

Many thanks in advance to anyone willing to help...

1
Please post a complete code example. (Your use of this-> suggests that this code occurs at class scope, but there is no class declaration in your code.) - HighCommander4
Also, CDT's ability to understand standard library code like std::index_sequence will depend on which standard library version you're using, which in turn is usually coupled to the compiler version, so please state what compiler version you're using. - HighCommander4
@HC4-reinstateMonica I have added a complete example where Eclipse is reporting the same problem. Compiler version has been publiched as well. - Martin Kopecký
Thanks, I can reproduce the problem now. It seems to be related to the fact that newer versions of gcc's standard library use a compiler intrinsic called __integer_pack in their implementation of std::index_sequence, which Eclipse CDT does not understand. - HighCommander4
I updated the answer to reflect the fact the bug has now been fixed in Eclipse CDT. - HighCommander4

1 Answers

1
votes

The problem is caused by the fact that the standard library that comes with gcc 8 and newer uses a new compiler intrinsic called __integer_pack to implement std::make_integer_sequence (and related utilities like std::make_index_sequence).

Eclipse CDT's parser does not currently understand the __integer_pack intrinsic, and therefore it has trouble correctly parsing code that uses std::make_integer_sequence / std::make_index_sequence with these newer gcc versions.

I filed a CDT bug to track adding support for the __integer_pack intrinsic.

Meanwhile, a workaround you could employ is to use gcc 7 or older. If you need gcc 8 or newer to actually build your code, you could still tell Eclipse the look at the standard library headers of e.g. gcc 7 by replacing ${COMMAND} in the mentioned "built-in compiler settings" configuration with g++-7.

UPDATE: The Eclipse bug is now fixed, with the fix targeting CDT's 9.11 release (scheduled to be part Eclipse 2020-03).