================
@@ -235,3 +276,13 @@ void Negative() {
   if (MACRO(x) == nullptr)
     ;
 }
+
+void test_redundant_get() {
+  std::vector<std::shared_ptr<int>> v;
+  auto f = [](int) {};
+  for (auto i = v.begin(); i != v.end(); ++i) {
+    f(*i->get());
----------------
akshaykumars614 wrote:

I tried something like this but I am getting error
#include <memory>
#include <vector>

struct Inner {
  int getValue() const { return 42; }
};

struct Example {
  Inner inner;
  Inner* get() { return &inner; }
};

void test_redundant_get() {
  std::vector<std::shared_ptr<int>> v;
  auto f = [](int) {};
  for (auto i = v.begin(); i != v.end(); ++i) {
    f(**i);
  }
}

void test_redundant_get_with_member() {
  std::vector<std::shared_ptr<Example>> v;
  auto f = [](int) {};
  for (auto i = v.begin(); i != v.end(); ++i) {
    f(*i->get()->getValue());
  }
}

/home/akumar/llvm/a.cpp:29:18: error: no member named 'getValue' in 'Example' 
[clang-diagnostic-error]
   29 |     f(*i->get()->getValue());
      |        ~~~~~~~~  ^
      
      
  I am unable to get what wrong I am doing here

https://github.com/llvm/llvm-project/pull/98757
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to