This is the mail archive of the gcc-bugs@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: c++/9666: Arg conversion problem with operator new


Synopsis: Arg conversion problem with operator new

State-Changed-From-To: open->analyzed
State-Changed-By: bangerth
State-Changed-When: Fri Feb 14 21:22:28 2003
State-Changed-Why:
    Confirmed -- well, sort of, since I am not sure whether this
    is legal. Here's the code slightly reformatted:
    -------------------------
    #include        <cstddef>
    
    struct  X {
        operator size_t ();
        operator size_t () const;
    };
    
    char *f2 (const X &x) { return new char[x]; }
    --------------------------
    The compiler complains:
    tmp/g> /home/bangerth/bin/gcc-3.4-pre/bin/c++ -c x.cc
    x.cc: In function `char* f2(const X&)':
    x.cc:8: error: expression in new-declarator must have integral or enumeration
       type
    
    Now, I tend to think that the code is illegal, due to 5.3.4.7:
    7 Every constant-expression in a direct-new-declarator shall be an inte-
      gral  constant  expression  (_expr.const_)  and evaluate to a strictly
      positive value.  The expression in a direct-new-declarator shall  have
      integral type (_basic.fundamental_) with a non-negative value.
    
    
    Then, on the other hand, this code compiles:
    -----------------------
    #include        <cstddef>
    
    struct  X {
    /*  operator size_t (); */
        operator size_t () const;
    };
    
    char *f2 (const X &x) { return new char[x]; }
    -----------------------
    I should think that the presence of the second non-const 
    operator shouldn't make a difference since x is a constant
    reference...
    
    Can someone clarify?
    
    W.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9666


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