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

Invalid use of non-static data member 'offset' #3719

Closed
springmeyer opened this issue Feb 15, 2017 · 2 comments
Closed

Invalid use of non-static data member 'offset' #3719

springmeyer opened this issue Feb 15, 2017 · 2 comments

Comments

@springmeyer
Copy link
Contributor

springmeyer commented Feb 15, 2017

@ghoshkaj noticed that include/util/indexed_data.hpp will not compile with clang++ via xcode 7 on circleci's OS X infrastructure over at Project-OSRM/node-osrm#296 (comment). The workaround was to upgrade to xcode 8 on circle. This issue stands to track the underlying issue and decide how to avoid it in the future.

The problem appears that code which landed in #3585 will not compile on all versions of OS X.

I was able to replicate with this testcase:

#include <iostream>
#include <limits>

struct VariableGroupBlock
{

    struct BlockReference
    {
        std::uint32_t offset;
        std::uint32_t descriptor;
    };

    VariableGroupBlock() {}

    std::size_t max() const {
        return std::numeric_limits<decltype(BlockReference::offset)>::max();
    }
};

int main() {

    VariableGroupBlock bg;
    std::clog << bg.max() << "\n";
    
}
$ clang++ testcase.cpp
testcase.cpp:16:61: error: invalid use of non-static data member 'offset'
        return std::numeric_limits<decltype(BlockReference::offset)>::max();
                                            ~~~~~~~~~~~~~~~~^~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:605:36: note: expanded from macro 'decltype'
#  define decltype(__x) __decltype(__x)
                                   ^~~
1 error generated.

I can workaround by adding the -std=c++1y or -std=c++11 flag.

I see this behavior with this version of clang++ and xcode:

$ clang++ -v
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ xcodebuild -version
Xcode 8.2.1
Build version 8C1002

I presume what is happening is that despite the -std=c++1y being added in the osrm-backend builds, the clang++ version in xcode 7 must be missing some C++11 support.

Next steps:

  • Run this test on older OS X, narrow down the issue
  • Consider adding a cmake configure check to ensure a working clang++/xcode version is available, rather than suffering from a compiler error later on

/cc @danpat

@springmeyer
Copy link
Contributor Author

I created a repo with the testcase (https://github.com/springmeyer/invalid-use-of-non-static-data-test) and tried testing on travis ci. So far I've found that xcode 7 on travis works fine (https://travis-ci.org/springmeyer/invalid-use-of-non-static-data-test) so this may be something specific to the circleci version.

@springmeyer
Copy link
Contributor Author

The testcase also works on circleci with xcode 7.3 (https://circleci.com/gh/mapbox/invalid-use-of-non-static-data-test/3). So this is starting to feel like a bug not worth digging into more. Going to close without any action.

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

No branches or pull requests

1 participant