Bug 381000 - [gcc] support for compiler type trait intrinsics like __is_pod
Summary: [gcc] support for compiler type trait intrinsics like __is_pod
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 8.1.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on: 342683 485720 528072
Blocks: 367993
  Show dependency tree
 
Reported: 2012-05-30 05:09 EDT by Nathan Ridge CLA
Modified: 2020-09-04 15:18 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Ridge CLA 2012-05-30 05:09:25 EDT
GCC implements C++11 type traits metafunctions like std::is_pod using corresponding compiler intrinsics like __is_pod.

In order for CDT to correctly index code using these type traits metafunctions, it needs to be able to recognize and evaluate these instrinsics.

Here is an example of code that currently gives a false positive error:

template <bool> struct foo {};
template <> struct foo<true> { typedef int type; };
typedef foo<__is_pod(int)>::type t;  // ERROR HERE

(Here I unwrapped the use of std::is_pod and used the intrinsic directly, but the error is the same if you use std::is_pod).

The error is: "Type 'foo<__is_pod(int)>::type' could not be resolved" (because CDT does not realize that __is_pod(int) evaluates to true, and so looks in the main template 'foo' rather than the specialization 'foo<true>', and the main template does not have a 'type' member).

I have already reported bug 367993 for a more complex use case that also needs support for dependent expressions; however, simple use cases like the above don't need support for dependent expressions.

Here is a list of type traits intrinsics used by GCC as of version 4.7:
  __is_pod
  __is_trivial
  __is_standard_layout
  __is_literal_type
  __is_enum
  __is_union
  __is_class
  __is_empty
  __is_polymorphic
  __is_abstract
  __is_base_of
  __has_trivial_constructor
  __has_trivial_copy
  __has_trivial_assign
  __has_trivial_destructor
  __has_nothrow_constructor
  __has_nothrow_copy
  __has_nothrow_assign
  __has_virtual_destructor

(I assume it would be a bit of overkill to file a bug for each one...)
Comment 1 Nathan Ridge CLA 2012-05-30 05:18:02 EDT
I should mention that the specifications for the type traits that these intrinsics implement can be found in the C++11 standard, sections 20.9.4 and 20.9.6.
Comment 2 Markus Schorn CLA 2012-05-30 10:26:19 EDT
The intrinsics are supported by CDT (bug 342683), however the evaluation of such expressions is not implemented.
Comment 3 Martin Oberhuber CLA 2017-11-30 09:52:40 EST
Using CDT-9.4 (Oxygen.2rc2), it looks like the original issue from comment #0 is resolved. At least the sample code doesn't error out any more. And I see some implementation in GNUCPPSourcerParser.parseTypeTrait() . So this bug can probably be closed now.

As a follow-up: indexing a simple project with just #include <iostream> on Ubuntu 17 shows 3 errors like this in the log:

    Indexer: unresolved name at /usr/include/c++/6/type_traits(1361);
    A template id provides illegal arguments for the instantiation:     integral_constant

On investigation, it turns out that this is due to the following missing builtin:

    __is_trivially_constructible

As a workaround, I went to Project Properties > C/C++ > Preprocessor Include Paths, Macros etc > GNU C++ > CDT User Settings Entries, and added a "Preprocessor Macros File" in my workspace. The file name is 
"eclipse-indexer-workarounds.h" and it has following line:

#define __is_trivially_constructible(A, ...) (true)
Comment 4 Nathan Ridge CLA 2017-11-30 17:11:57 EST
The bug remains open to track implementation of some remaining type trait intrinsics like __is_trivially_constructible.

I edited the bug title to clarify that we're just talking about type trait intrinsics in this bug, not other kinds of intrinsics.
Comment 5 Nathan Ridge CLA 2017-12-03 15:14:15 EST
I implemented evaluation of __is_trivially_constructible in bug 528072.

Other intrinsics whose evaluation needs to be implemented are:
  __has_nothrow_assign
  __has_nothrow_copy
  __has_nothrow_constructor
  __has_trivial_assign
  __has_trivial_constructor
  __has_trivial_destructor
  __is_literal_type
  __is_trivially_assignable

Once those are implemented as well, this bug can be closed.