Thanks for the testcase. Filed bug 
https://bugzilla.mozilla.org/show_bug.cgi?id=444617

Taras

Philip Taylor wrote:
> I've been playing around with Dehydra a bit, and wanted to make it
> warn whenever a copy constructor is used for a function call argument.
> So I have C++ code like:
>
>     struct t {
>         t(const char* v);
>         t(const t& v);
>         const char* data;
>     };
>
>     t f(t v);
>     t g(const t& v);
>
>     int main() {
>         t a("test");
>
>         f(a);
>
>         g(f(a));
>
>         a = f(a);
>     }
>
> and want it to complain about all those f(a) calls. So I have a script
> like:
>
>     function find_ctor_calls(loc, v) {
>         if (v.isFcall) {
>             warning("# Fcall '" + v.name + "' with " +
> v.arguments.length + " args", loc);
>             for each (var arg in v.arguments) {
>                 if (arg.isConstructor)
>                     warning("Constructor '" + arg.name + "' used in
> argument to '" + v.name + "'", loc);
>                 find_ctor_calls(loc, arg);
>             }
>         }
>         if (v.assign) {
>             for each (var v2 in v.assign)
>                 find_ctor_calls(loc, v2);
>         }
>     }
>
>     function process_function(decl, body) {
>         for each (var stmts in body)
>             for each (var stmt in stmts.statements)
>                 find_ctor_calls(stmts.loc, stmt);
>     }
>
> which outputs (using dehydra-gcc 5435efc32dad):
>
>     test.cpp:11: warning: # Fcall 't::t(const char*)' with 1 args
>     test.cpp:13: warning: # Fcall 'f(t)' with 1 args
>     test.cpp:13: warning: Constructor 't::t(const t&)' used in
> argument to 'f(t)'
>     test.cpp:13: warning: # Fcall 't::t(const t&)' with 1 args
>     test.cpp:15: warning: # Fcall 'g(const t&)' with 1 args
>     test.cpp:15: warning: # Fcall 'f(t)' with 0 args
>     test.cpp:17: warning: # Fcall 'f(t)' with 0 args
>
> It only finds the first f(a), because in the last two cases Dehydra
> appears to skip the arguments to f (according to the "Fcall f(t) with
> 0 args" lines). Is that a bug in Dehydra, or a feature, or am I just
> using it wrong?
> _______________________________________________
> Dev-static-analysis mailing list
> [email protected]
> https://lists.mozilla.org/listinfo/dev-static-analysis
>   

_______________________________________________
Dev-static-analysis mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-static-analysis

Reply via email to