1998-10-04 Mark Mitchell <mark@markmitchell.com>
+ * call.c (build_over_call): Make pedwarns about dropped qualifiers
+ into full-fledged errors.
+ * cvt.c (convert_to_reference): Likewise.
+ * typeck.c (convert_for_assignment): Likewise.
+
* search.c (expand_upcast_vtables): In addition to unsetting
TREE_READONLY, remove top-level const type qualifier.
char *p = (dv && dc ? "const and volatile"
: dc ? "const" : dv ? "volatile" : "");
- cp_pedwarn ("passing `%T' as `this' argument of `%#D' discards %s",
- TREE_TYPE (argtype), fn, p);
+ cp_error ("passing `%T' as `this' argument of `%#D' discards %s",
+ TREE_TYPE (argtype), fn, p);
}
/* [class.mfct.nonstatic]: If a nonstatic member function of a class
X is called for an object that is not of type X, or of a type
tree ttl = TREE_TYPE (reftype);
tree ttr = lvalue_type (expr);
- if (! real_lvalue_p (expr) && ! TYPE_READONLY (ttl))
+ /* [dcl.init.ref] says that if an rvalue is used to
+ initialize a reference, then the reference must be to a
+ non-volatile const type. */
+ if (! real_lvalue_p (expr)
+ && (!TYPE_READONLY (ttl) || TYPE_VOLATILE (ttl)))
{
- if (decl)
- /* Ensure semantics of [dcl.init.ref] */
- cp_pedwarn ("initialization of non-const reference `%#T' from rvalue `%T'",
- reftype, intype);
+ char* msg;
+
+ if (TYPE_VOLATILE (ttl) && decl)
+ msg = "initialization of volatile reference type `%#T'";
+ else if (TYPE_VOLATILE (ttl))
+ msg = "conversion to volatile reference type `%#T'";
+ else if (decl)
+ msg = "initialization of non-const reference type `%#T'";
else
- cp_pedwarn ("conversion to non-const `%T' from rvalue `%T'",
- reftype, intype);
+ msg = "conversion to non-const reference type `%#T'";
+
+ cp_error (msg, reftype);
+ cp_error ("from rvalue of type `%T'", intype);
}
else if (! (convtype & CONV_CONST))
{
if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
- cp_pedwarn ("conversion from `%T' to `%T' discards const",
- ttr, reftype);
+ cp_error ("conversion from `%T' to `%T' discards const",
+ ttr, reftype);
else if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
- cp_pedwarn ("conversion from `%T' to `%T' discards volatile",
- ttr, reftype);
+ cp_error ("conversion from `%T' to `%T' discards volatile",
+ ttr, reftype);
}
}
if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
{
if (fndecl)
- cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
- rhstype, parmnum, fndecl);
+ cp_error ("passing `%T' as argument %P of `%D' discards const",
+ rhstype, parmnum, fndecl);
else
- cp_pedwarn ("%s to `%T' from `%T' discards const",
- errtype, type, rhstype);
+ cp_error ("%s to `%T' from `%T' discards const",
+ errtype, type, rhstype);
}
if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
{
if (fndecl)
- cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
- rhstype, parmnum, fndecl);
+ cp_error ("passing `%T' as argument %P of `%D' discards volatile",
+ rhstype, parmnum, fndecl);
else
- cp_pedwarn ("%s to `%T' from `%T' discards volatile",
- errtype, type, rhstype);
+ cp_error ("%s to `%T' from `%T' discards volatile",
+ errtype, type, rhstype);
}
}
if (string_conv_p (type, rhs, 1))
/* converting from string constant to char *, OK. */;
else if (fndecl)
- cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
- rhstype, parmnum, fndecl);
+ cp_error ("passing `%T' as argument %P of `%D' discards const",
+ rhstype, parmnum, fndecl);
else
- cp_pedwarn ("%s to `%T' from `%T' discards const",
+ cp_error ("%s to `%T' from `%T' discards const",
errtype, type, rhstype);
}
else if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
{
if (fndecl)
- cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
+ cp_error ("passing `%T' as argument %P of `%D' discards volatile",
rhstype, parmnum, fndecl);
else
- cp_pedwarn ("%s to `%T' from `%T' discards volatile",
+ cp_error ("%s to `%T' from `%T' discards volatile",
errtype, type, rhstype);
}
else if (TREE_CODE (ttl) == TREE_CODE (ttr)
if (const_parity)
{
if (fndecl)
- cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
- rhstype, parmnum, fndecl);
+ cp_error ("passing `%T' as argument %P of `%D' discards const",
+ rhstype, parmnum, fndecl);
else
- cp_pedwarn ("%s to `%T' from `%T' discards const",
+ cp_error ("%s to `%T' from `%T' discards const",
errtype, type, rhstype);
}
if (volatile_parity)
{
if (fndecl)
- cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
- rhstype, parmnum, fndecl);
+ cp_error ("passing `%T' as argument %P of `%D' discards volatile",
+ rhstype, parmnum, fndecl);
else
- cp_pedwarn ("%s to `%T' from `%T' discards volatile",
- errtype, type, rhstype);
+ cp_error ("%s to `%T' from `%T' discards volatile",
+ errtype, type, rhstype);
}
if (unsigned_parity > 0)
{
#include <string>
class foo {public: foo () {}};
-class bar {public: bar (foo& dflt);};
+class bar {public: bar (const foo& dflt);};
class baz: public bar {public: baz (): bar (foo ()) {}};
extern "C" void printf (char *, ...);
struct base {
- int data_member;
+ mutable int data_member;
base () {}
- void function_member ();
+ void function_member () const;
};
base base_object;
int main ()
{
- base& base_ref = base_returning_function ();
+ const base& base_ref = base_returning_function ();
base_ref.function_member ();
base_ref.function_member ();
return local_base_object;
}
-void base::function_member ()
+void base::function_member () const
{
}
typedef void (*GctNameRefProcedure)(GctNameRef&);
typedef GctNameRef (*GctNameRefMapper)(GctNameRef&);
-typedef GctNameRef (*GctNameRefCombiner)(GctNameRef&, GctNameRef&);
+typedef GctNameRef& (*GctNameRefCombiner)(const GctNameRef&,
+ const GctNameRef&);
typedef int (*GctNameRefPredicate)(GctNameRef&);
typedef int (*GctNameRefComparator)(GctNameRef&, GctNameRef&);
GctNameRefList();
GctNameRefList(GctNameRef& head);
GctNameRefList(GctNameRef& head, GctNameRefList& tl);
- GctNameRefList(GctNameRefList& a);
+ GctNameRefList(const GctNameRefList& a);
GctNameRefList(Pix p);
~GctNameRefList();
- GctNameRefList& operator = (GctNameRefList& a);
+ GctNameRefList& operator = (const GctNameRefList& a);
int null();
int valid();
}
-inline GctNameRefListNode* newGctNameRefListNode(GctNameRef& h)
+inline GctNameRefListNode* newGctNameRefListNode(const GctNameRef& h)
{
GctNameRefListNode* p = new GctNameRefListNode;
p->ref = 1;
- p->hd = h;
+ p->hd = (GctNameRef&) h;
return p;
}
reference(P->tl);
}
-inline GctNameRefList::GctNameRefList(GctNameRefList& a)
+inline GctNameRefList::GctNameRefList(const GctNameRefList& a)
{
- reference(a.P);
+ GctNameRefList& gl = (GctNameRefList&) a;
+ reference(gl.P);
P = a.P;
}
static init_NilGctNameRefListNode NilGctNameRefListNode_initializer;
-GctNameRefList& GctNameRefList::operator = (GctNameRefList& a)
+GctNameRefList& GctNameRefList::operator = (const GctNameRefList& a)
{
reference(a.P);
dereference(P);
--- /dev/null
+// Build don't link:
+
+int f();
+
+void g()
+{
+ const int& i = f(); // OK
+ int& j = f(); // ERROR - initialization of non-const reference
+ const volatile int& k = f(); // ERROR - initialization of volatile ref
+}