[cfe-dev] Same AST for is_same<char, int>::value and is_same<char, long>::value

David Rector via cfe-dev cfe-dev at lists.llvm.org
Tue Nov 23 14:38:32 PST 2021


Comparing the getQualifier()->getAsRecordDecl()s of the two DeclRefExprs should do it I think (untested).  Careful though, NNS::getAsRecordDecl() crashes instead of returning null if the qualifier is e.g. a namespace, check its implem for the permissible kinds (or maybe better to add a getAsRecordDeclUnsafe() method).

> On Nov 23, 2021, at 11:03 AM, Benics Balázs via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> 
> (Resending from my personal email address)
> 
> 
> From: Balázs Benics <balazs.benics at sigmatechnology.se>
> Sent: Tuesday, November 23, 2021, 14:45
> To: cfe-dev
> Subject: Same AST for is_same::value and is_same::value
> 
> I seek some advice on the following AST scenario.
> https://godbolt.org/z/WcTeoGcbG
>  
> 1  #include <type_traits>
> 2  using std::is_same;
> 3  bool top() {
> 4    return is_same<char, int>::value || is_same<char, long>::value;
> 5  }
>  
> The `alpha.core.IdenticalExpr` static analyzer checker warns about that the two `..::value` are identical DeclRefExprs.
> According to the AST, they are indeed identical:
>  
>   BinaryOperator <col:10, col:60> 'bool' '||'
>   |-ImplicitCastExpr <col:10, col:30> 'bool':'bool' <LValueToRValue>
>   | `-DeclRefExpr <col:10, col:30> 'const bool':'const bool' lvalue Var 0x563b67cde0a8 'value' 'const bool':'const bool'
>   `-ImplicitCastExpr <col:39, col:60> 'bool':'bool' <LValueToRValue>
>     `-DeclRefExpr <col:39, col:60> 'const bool':'const bool' lvalue Var 0x563b67cde0a8 'value' 'const bool':'const bool'
>  
> Both of them refers to the same `VarDecl`, corresponding (probably) to the `std::false_type::value`.
>  
> How can I detect that even though the `values` look similar, they correspond to different template instances in that sense?
> What do you suggest?
> In the end, I want to suppress these reports in the static analyzer.
>  
> Balázs
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20211123/369d811c/attachment-0001.html>


More information about the cfe-dev mailing list