ayushpareek2003 wrote: > I feel `.clear()` should have a similar semantic with `= {};`. It will be > confusing for people to understand this. It will be helpful if you can > provide a test to show the difference.
I’ve tried to demonstrate the difference between .clear() and = {}, not a formal test case, but just a minimal example to illustrate the behavior clearly. It’s meant to show how these two approaches behave differently, especially when dealing with types like std::optional. ` std::optional<std::string> A = "clang"; auto B = A; auto C = A; B->clear(); // empties the string but keeps the optional engaged C = {}; // fully resets the optional to disengaged (nullopt) std::cout << "B has value? " << B.has_value() << "\n"; // it will print 1 std::cout << "C has value? " << C.has_value() << "\n"; // it will print 0 ` I hope it helps clarify why = {} can be a safer and more expressive choice in some situations https://github.com/llvm/llvm-project/pull/138256 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits