From f0741626a15b41fd7fe4e7e4899cbdde9be37497 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Wed, 2 Jun 2021 07:57:13 -0700 Subject: [PATCH] [clang] fix order of parameters in some inherited constructors Summary: Some funky C++ way of calling the parent's constructor triggers a function in the frontend that used to reverse the order of parameters. Reviewed By: skcho Differential Revision: D28832500 fbshipit-source-id: 1032de2ca --- infer/src/clang/cTrans.ml | 4 ++-- infer/tests/codetoanalyze/cpp/pulse/frontend.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index bcfd7a4c1..174aa2774 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -223,8 +223,8 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s let attr = Procdesc.get_attributes pdesc in let procname = Procdesc.get_proc_name pdesc in attr.formals (* remove this, which should always be the first formal parameter *) |> List.tl_exn - |> List.fold_left ~init:([], []) - ~f:(fun (forwarded_params, forwarded_init_exps) (formal, typ) -> + |> List.fold_right ~init:([], []) + ~f:(fun (formal, typ) (forwarded_params, forwarded_init_exps) -> let pvar = Pvar.mk formal procname in let id = Ident.create_fresh Ident.knormal in ( (Exp.Var id, typ) :: forwarded_params diff --git a/infer/tests/codetoanalyze/cpp/pulse/frontend.cpp b/infer/tests/codetoanalyze/cpp/pulse/frontend.cpp index bae143d8b..4ce95c469 100644 --- a/infer/tests/codetoanalyze/cpp/pulse/frontend.cpp +++ b/infer/tests/codetoanalyze/cpp/pulse/frontend.cpp @@ -241,4 +241,19 @@ void FP_init_single_field_struct_ok() { } } +struct Base { + Base(int* p1, int* p2) { *p1 = 42; } +}; + +struct ForwardConstructorParams : Base { + // check that the parameters are forwarded in the correct order by the + // frontend + using Base::Base; +}; + +void derived_constructor_forwards_param_ok() { + int x; + ForwardConstructorParams A{&x, NULL}; +} + } // namespace frontend