Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

Build fails on MacOS with "reference to 'string_view' is ambiguous" #390

Closed
cajun-rat opened this issue Feb 1, 2018 · 8 comments
Closed

Comments

@cajun-rat
Copy link
Contributor

Since commit #0dda8cc61dd483535d2b8eb1548b87765d977436 the cquery build fails on Mac with the following error:

[ 5/77] Compiling src/clang_translation_unit.cc
In file included from ../../src/clang_translation_unit.cc:1:
In file included from ../../src/clang_translation_unit.h:3:
In file included from ../../src/clang_cursor.h:3:
In file included from ../../src/position.h:7:
../../src/serializer.h:349:60: error: reference to 'string_view' is ambiguous
void ReflectMember(Reader& visitor, const char* name, std::string_view& view);
                                                           ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string_view:736:37: note: candidate found by name lookup is 'std::__1::string_view'
typedef basic_string_view<char>     string_view;
                                    ^
../../third_party/string_view.hpp:48:38: note: candidate found by name lookup is 'std::string_view'
            using std::experimental::string_view;
                                     ^
In file included from ../../src/clang_translation_unit.cc:1:
In file included from ../../src/clang_translation_unit.h:3:
In file included from ../../src/clang_cursor.h:3:
In file included from ../../src/position.h:7:
../../src/serializer.h:350:60: error: reference to 'string_view' is ambiguous
void ReflectMember(Writer& visitor, const char* name, std::string_view& view);
                                                           ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string_view:736:37: note: candidate found by name lookup is 'std::__1::string_view'
typedef basic_string_view<char>     string_view;
                                    ^
../../third_party/string_view.hpp:48:38: note: candidate found by name lookup is 'std::string_view'
            using std::experimental::string_view;
                                     ^
2 errors generated.

I'm guessing this is a conflict between the polyfill that is shipped in third_party and whatever xcode is shipping.

I managed to make the build pass by hacking string_view.hpp to always include the platform string_view:

diff --git a/third_party/string_view.h b/third_party/string_view.h
index e0067ba..22b1168 100644
--- a/third_party/string_view.h
+++ b/third_party/string_view.h
@@ -1,6 +1,5 @@
 #if __cplusplus < 201703L
-#define STX_NAMESPACE_NAME std
-#include "string_view.hpp"
+#include <string_view>
 #else
 #include <string_view>
 #endif

This is clearly not a real solution, but does suggest that the problem is related to autodetection of when the polyfill is needed. I'm not sure what the best solution for this is though

@acowley
Copy link
Contributor

acowley commented Feb 1, 2018

You can add CXXFLAGS="-std=c++1z" to the environment before you build. I did this for nix on macOS here.

@scturtle
Copy link
Contributor

scturtle commented Feb 1, 2018

A proposal:

#ifndef __has_include
#define __has_include(inc) 0
#endif

#if __cplusplus >= 201703L || __has_include(<string_view>)
#include <string_view>
#else
#define STX_NAMESPACE_NAME std
#include "string_view.hpp"
#endif

@jacobdufault
Copy link
Owner

sg, or we just disable automatically including the system one.

@MaskRay
Copy link
Contributor

MaskRay commented Feb 1, 2018

314740a

@Sarcasm
Copy link
Contributor

Sarcasm commented Feb 1, 2018

I have errors too on Linux with Clang 5.0.1 and libstdc++ 7.2.1.
The code compiles with -std=c++11, so I think the string_view feature is not enabled, but still the header exists (has_include will return true, but once the header is included string_view is not available).

Compile error:

[ 2/77] Compiling src/query_utils.cc
In file included from ../../src/query_utils.cc:1:
In file included from ../../src/query_utils.h:5:
In file included from ../../src/query.h:3:
In file included from ../../src/indexer.h:3:
In file included from ../../src/clang_cursor.h:3:
In file included from ../../src/position.h:7:
../../src/serializer.h:180:36: error: no type named 'string_view' in namespace 'std'
void Reflect(Reader& visitor, std::string_view& view);
                              ~~~~~^
../../src/serializer.h:181:36: error: no type named 'string_view' in namespace 'std'
void Reflect(Writer& visitor, std::string_view& view);
                              ~~~~~^
In file included from ../../src/query_utils.cc:1:
In file included from ../../src/query_utils.h:5:
In file included from ../../src/query.h:3:
In file included from ../../src/indexer.h:7:
In file included from ../../src/clang_utils.h:3:
../../src/language_server_api.h:205:8: error: no type named 'string_view' in namespace 'std'
  std::string_view name;
  ~~~~~^
../../src/language_server_api.h:208:8: error: no type named 'string_view' in namespace 'std'
  std::string_view containerName;
  ~~~~~^
../../src/language_server_api.h:598:8: error: no type named 'string_view' in namespace 'std'
  std::string_view language;
  ~~~~~^
../../src/language_server_api.h:599:8: error: no type named 'string_view' in namespace 'std'
  std::string_view value;
  ~~~~~^
../../src/language_server_api.h:601:42: error: no member named 'string_view' in namespace 'std'
using lsMarkedString = std::variant<std::string_view, lsMarkedString1>;
                                    ~~~~~^
In file included from ../../src/query_utils.cc:1:
In file included from ../../src/query_utils.h:5:
In file included from ../../src/query.h:3:
../../src/indexer.h:202:8: error: no type named 'string_view' in namespace 'std'
  std::string_view ShortName() const {
  ~~~~~^
../../src/indexer.h:203:17: error: no member named 'string_view' in namespace 'std'
    return std::string_view(detailed_name.c_str() + short_name_offset,
           ~~~~~^
../../src/indexer.h:303:8: error: no type named 'string_view' in namespace 'std'
  std::string_view ShortName() const {
  ~~~~~^
../../src/indexer.h:304:17: error: no member named 'string_view' in namespace 'std'
    return std::string_view(detailed_name.c_str() + short_name_offset,
           ~~~~~^
../../src/indexer.h:428:8: error: no type named 'string_view' in namespace 'std'
  std::string_view ShortName() const {
  ~~~~~^
../../src/indexer.h:429:17: error: no member named 'string_view' in namespace 'std'
    return std::string_view(detailed_name.c_str() + short_name_offset,
           ~~~~~^
../../src/indexer.h:560:34: error: no type named 'string_view' in namespace 'std'
                            std::string_view unqualified_name);
                            ~~~~~^
In file included from ../../src/query_utils.cc:1:
In file included from ../../src/query_utils.h:5:
../../src/query.h:366:20: error: no member named 'string_view' in namespace 'std'
  std::vector<std::string_view> detailed_names;
              ~~~~~^
../../src/query.h:367:20: error: no member named 'string_view' in namespace 'std'
  std::vector<std::string_view> short_names;
              ~~~~~^
../../src/query.h:393:33: error: no type named 'string_view' in namespace 'std'
                           std::string_view short_name,
                           ~~~~~^
../../src/query.h:394:33: error: no type named 'string_view' in namespace 'std'
                           std::string_view detailed_name);
                           ~~~~~^
In file included from ../../src/query_utils.cc:1:
In file included from ../../src/query_utils.h:5:
In file included from ../../src/query.h:3:
In file included from ../../src/indexer.h:3:
In file included from ../../src/clang_cursor.h:3:
In file included from ../../src/position.h:7:
In file included from ../../src/serializer.h:6:
In file included from ../../third_party/optional.h:4:
../../third_party/optional.hpp:403:44: error: type 'OptionalBase<lsSymbolInformation>' (aka 'std::experimental::optional_base<lsSymbolInformation>') is not a direct or virtual base of 'std::experimental::optional<lsSymbolInformation>'
  constexpr optional(nullopt_t) noexcept : OptionalBase<T>() {};
                                           ^~~~~~~~~~~~~~~
../../src/query_utils.cc:429:16: note: in instantiation of member function 'std::experimental::optional<lsSymbolInformation>::optional' requested here
        return nullopt;
               ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

@jacobdufault
Copy link
Owner

We should just disable using the system header. Headache for no good reason imo.

@Sarcasm
Copy link
Contributor

Sarcasm commented Feb 1, 2018

I agree.
If the bundle implement works, there is no real benefit from the system one as both need to be supported anyway, and I don't think quality of implementation will change a lot of things here.

@MaskRay
Copy link
Contributor

MaskRay commented Feb 1, 2018

I think some headers pull in <optional> or <string_view> automatically (despite not C++17 ), which conflicts with third_party/optional.hpp or third_party/string_view.hpp

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

No branches or pull requests

6 participants