@Jason – The idea is make semantics.cc's maybe_convert_cond callable from parser.cc + pt.cc, i.e. to make it a non-static function. Any reasons not do so?
Sandra Loosemore wrote:
[…] By using the existing front-end hooks for the implicit conversion to bool in conditional expressions, we also get free support for using a C++ class object that has a bool conversion operator in the user/condition selector.
Can you also add type-dependent testcases? They seem to work fine, but are missing. Like template<typename T, typename T2> void f(T x, T2 y) { #pragma omp metadirective when(user={condition(x)}, target_device={device_num(y)} : flush) } plus calls to them. * * * In parser.cc and pt.cc, you don't call maybe_convert_cond (because it is currently accessible) - but by calling some of its ingredients, you bypass some code. I discussed with Jakub and the idea is (see top of the page) to make maybe_convert_cond non-static and use it instead. Additionally, it seems as if we should add if (!processing_template_decl) t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); as we do for the other clauses.
gcc/c/ChangeLog * c-parser.cc (c_parser_omp_context_selector): Call convert_lvalue_to_rvalue and c_objc_common_truthvalue_conversion on the expression for OMP_TRAIT_PROPERTY_BOOL_EXPR. gcc/cp/ChangeLog * parser.cc (cp_parser_omp_context_selector): Call convert_from_reference and condition_conversion on the expression for OMP_TRAIT_PROPERTY_BOOL_EXPR. * pt.cc (tsubst_omp_context_selector): Likewise. gcc/testsuite/ChangeLog * c-c++-common/gomp/declare-variant-2.c: Update expected output. * c-c++-common/gomp/metadirective-condition-constexpr.c: New. * c-c++-common/gomp/metadirective-condition.c: New. * c-c++-common/gomp/metadirective-error-recovery.c: Update expected output. * g++.dg/gomp/metadirective-condition-class.C: New.
Otherwise, it looks good to me. Thanks, Tobias