1

I developed some ANTLR + LLVM parser code in spring. Since it is only a recreational project, I did not touch the code or see whether it compiles in the meantime. During that time, several system updates took place, which I assume caused my current problems:

When trying to compile the code today (with clang++), I suddenly got several error messages. Initially the std::any class was not found at all. I then played with "std=c++17" and "std=c++20" options. Now the main error (as I understand it) seems to be

error: no member named 'as' in 'std::any' 

The error occurs whenever i do something like for instance

args.push_back(visit(*it).as<sarg>());

or, more stripped-down:

antlrcpp::Any myvar;
//...
myvar.as<some_type>();

I picked this up from Antlr tutorial codes where this seems to be the standard idiom to cast an antlrcpp::Any object to the type desired by the calling function.

I noticed that antlrcpp::Any apparently is merely a wrapper for std::any, which apparently really does not support this "as" method.

What can i do to make my code work again?

  • `std::any` has never had a method `as` AFAIK, but guessing it seems that `std::any_cast(myvar)` is what you are looking for. – john Aug 15 '22 at 18:33
  • I suspect you're looking for [`std::any_cast`](https://en.cppreference.com/w/cpp/utility/any/any_cast). – G.M. Aug 15 '22 at 18:34
  • 1
    anltr any used to be its own implementation , including 'as', as of late last year is is now just a 'using' of stfd::any, so 'as' disapperaed – pm100 Aug 15 '22 at 18:35
  • Thank you - I was suspecting something like that, but was hoping that I could avoid the refactoring to the use of ```any_cast`` ... – Wave and Matter Aug 15 '22 at 21:10

0 Answers0