This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch][c++/PR 31743]


Hi Mark,

Thanks for reviewing this.

Mark Mitchell wrote:
Thanks for working on this.  A cleaner fix would be to but a call to
require_complete_type in build_new (rather than build_new_1).

The TYPE argument to build_new is either the type being allocated, or
the type of the array elements.  In either case, it must be a complete
type.  So, after the other checks (for REFERENCE_TYPE and FUNCTION_TYPE)
in build_new, you could just do:

  type = require_complete_type (type);
  if (type == error_mark_node)
    return error_mark_node;

Then, remove the complete_type_or_else call from build_new_1. (The only
caller of build_new_1 is build_new.)
I tried this and it yields the inaccurate diagnostic
31743.C:2: error: cannot convert ‘int*’ to ‘int (*)[]’ in initialization

The problem is that require_complete_type expects an *expression* but the tree we have in build_new represents a *type*. require_complete_type goes on to test the completeness of TREE_TYPE (value) which, in this case is simply 'int' and so, it doesn't go on to call complete_type_or_else to generate the diagnostic that we want. I suppose I could create a dummy expression with the given type to pass to require_complete_type, but that seems a bit clunky.

I still believe that my patch is correct since build_new_1 is the place where the use of incomplete classes/structs are currently diagnosed and a similar (and correct) diagnostic is generated
31743.C:2: error: invalid use of array with unspecified bounds


Please see my more detailed rationale in the PR itself and let me know what you think.
Please also include a testcase with your submission.
Sorry. I figured the test case in the bug report was sufficient. Attaching a test case to this message.

Dave

Attachment: 31743.C
Description: application/unknown-content-type-c_auto_file


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]