================
@@ -23,8 +23,12 @@ void ProTypeUnionAccessCheck::registerMatchers(MatchFinder 
*Finder) {
 
 void ProTypeUnionAccessCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *Matched = Result.Nodes.getNodeAs<MemberExpr>("expr");
-  diag(Matched->getMemberLoc(),
-       "do not access members of unions; use (boost::)variant instead");
+  if (auto MemberLoc = Matched->getMemberLoc(); MemberLoc.isValid())
+    diag(MemberLoc,
+         "do not access members of unions; use (boost::)variant instead");
+  else
+    diag(Matched->getBeginLoc(),
+         "do not access members of unions; use (boost::)variant instead");
----------------
PiotrZSL wrote:

```suggestion
  SourceLocation Loc = Matched->getMemberLoc();
  if (Loc.isInvalid())
     Loc = Matched->getBeginLoc();
  diag(Loc, "do not access members of unions; use (boost::)variant instead");
```

re-format may be needed

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

Reply via email to