On Wed, 04 Mar 2020 11:16:35 -0500 David Malcolm <dmalc...@redhat.com> wrote:
> On Wed, 2020-03-04 at 11:05 -0500, Marek Polacek wrote: > > On Wed, Mar 04, 2020 at 04:54:54PM +0100, Bernhard Reutner-Fischer > > wrote: > > > On Mon, 2 Mar 2020 16:48:26 -0500 > > > David Malcolm <dmalc...@redhat.com> wrote: > > > > > > > +static inline bool > > > > +is_std_function_p (const_tree fndecl) > > > > +{ > > > > + tree name_decl = DECL_NAME (fndecl); > > > > + if (!name_decl) > > > > + return false; > > > > + if (!DECL_CONTEXT (fndecl)) > > > > + return false; > > > > + if (TREE_CODE (DECL_CONTEXT (fndecl)) != NAMESPACE_DECL) > > > > + return false; > > > > + tree ns = DECL_CONTEXT (fndecl); > > > > + if (!(DECL_CONTEXT (ns) == NULL_TREE > > > > + || TREE_CODE (DECL_CONTEXT (ns)) == TRANSLATION_UNIT_DECL)) > > > > + return false; > > > > + if (!DECL_NAME (ns)) > > > > + return false; > > > > + return id_equal ("std", DECL_NAME (ns)); > > > > +} > > > > > > Sounds a bit elaborate, doesn't? > > > I hope this is optimized to > > > > > > static inline bool > > > is_std_function_p (const_tree fndecl) > > > { > > > tree name_decl = DECL_NAME (fndecl); > > > if (!name_decl) > > > return false; Make the above if (!DECL_NAME (fndecl)) return false; > > > tree ns = DECL_CONTEXT (fndecl); > > > if (!ns) > > > return false; > > > if (TREE_CODE (ns) != NAMESPACE_DECL) > > > return false; > > > if (!(DECL_CONTEXT (ns) == NULL_TREE > > > || TREE_CODE (DECL_CONTEXT (ns)) == TRANSLATION_UNIT_DECL)) > > > return false; > > > if (!DECL_NAME (ns)) > > > return false; > > > return id_equal ("std", DECL_NAME (ns)); > > > } > > > > > > isn't "std" spelled out std_identifier() and is an identifier, i.e. > > > return DECL_NAME (ns) == std_identifier; ? > > > > We have decl_in_std_namespace_p for that. > > Thanks. Indeed the comment to the function quoted above which wasn't > quoted reads: > > /* Return true if FNDECL is within the namespace "std". > Compare with cp/typeck.c: decl_in_std_namespace_p, but this doesn't > rely on being the C++ FE (or handle inline namespaces inside of std). */ > > since as noted in my reply to Bernhard the analyzer runs in the middle- > end and thus can't rely on features of a specific frontend. > > Is there a better way to do this? yea probably not (my tree is obviously outdated, i still had std_identifier lying around here, sorry for that!) Still, to the bikeshedding question above, does CSE or whatever arrive at the same or wouldn't we want to phrase it more concisely as i tried to imply? thanks,