[clang] Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585, #111173)" (PR #111852)

via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 24 07:14:32 PDT 2024


steelannelida wrote:

There's a weird error after this change + #112381. It only reproduces with multiple modules

* Module 1, `dep_lib.h`:

```
#ifndef DEB_LIB_H_
#define DEB_LIB_H_

#include <string>
#include <vector>

namespace f{
template<typename T>
class strm;
namespace t {
template <typename T>
std::vector<T> A(strm<T> stream);
}

template<typename T>
class strm{
template <typename V>
friend std::vector<V> t::A(strm<V> stream);
};

template <typename T>
strm<T> B(std::vector<T> elems);

inline strm<std::string> B(
    std::initializer_list<const char*> elems) {
  return B(std::vector<std::string>(elems.begin(), elems.end()));
}
}
#endif  // DEB_LIB_H_

```

* Module 2, `another_lib.h`; depends on module 1

```
#ifndef ANOTHER_LIB_H_
#define ANOTHER_LIB_H_

#include "deb_lib.h"

namespace f {
namespace t {

template<typename T>
std::vector<T> A(strm<T> stream) {
  std::vector<T> ret;
  return ret;
}

}
}
#endif  // ANOTHER_LIB_H_
```

* Module 3, consists also of `another_lib.h` and depends on module 2.

* Binary (depends on Module 1 & 3):

```

#include <vector>

#include "another_lib.h"

namespace {

namespace {

struct E {};

}  // namespace

class T {
 protected:
  void momo() {
    f::strm<E> x;
    f::t::A(x);
  }
};

}  // namespace
int main(int argc, char** argv) { return 0; }
```

When compiling the binary, I'm getting:

```
another_lib.h:12:10: error: no viable conversion from returned value of type 'vector<std::string>' to function return type 'vector<(anonymous namespace)::(anonymous namespace)::E>'
   12 |   return ret;
      |          ^~~
test_lib.cc:18:11: note: in instantiation of function template specialization 'f::t::A<(anonymous namespace)::(anonymous namespace)::E>' requested here
   18 |     f::t::A(x);
      |           ^
/include/vector:558:55: note: candidate constructor not viable: no known conversion from 'std::vector<string>' to 'const vector<E> &' for 1st argument
  558 |   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x);
      |                                                       ^      ~~~~~~~~~~~~~~~~~
/include/vector:564:55: note: candidate constructor not viable: no known conversion from 'std::vector<string>' to 'initializer_list<value_type>' (aka 'initializer_list<(anonymous namespace)::(anonymous namespace)::E>') for 1st argument
  564 |   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(initializer_list<value_type> __il);
      |                                                       ^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/include/vector:575:55: note: candidate constructor not viable: no known conversion from 'std::vector<string>' to 'vector<E> &&' for 1st argument
  575 |   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(vector&& __x)
      |                                                       ^      ~~~~~~~~~~~~
/include/vector:447:64: note: explicit constructor is not a candidate
  447 |   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(const allocator_type& __a)
      |                                                                ^
/include/vector:456:64: note: explicit constructor is not a candidate
  456 |   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n) {
      |        
```

I'm still working on getting the full commandline from our build system, but maybe this gives some idea on what's wrong

https://github.com/llvm/llvm-project/pull/111852


More information about the cfe-commits mailing list