Commit e01ffb47 by Marek Polacek Committed by Marek Polacek

PR c++/88548 - this accepted in static member functions.

	* parser.c (cp_debug_parser): Adjust printing of
	local_variables_forbidden_p.
	(cp_parser_new): Set local_variables_forbidden_p to 0 rather than false.
	(cp_parser_primary_expression): When checking
	local_variables_forbidden_p, use THIS_FORBIDDEN or
	LOCAL_VARS_FORBIDDEN.
	(cp_parser_lambda_body): Update the type of
	local_variables_forbidden_p.  Set it to 0 rather than false.
	(cp_parser_condition): Adjust call to cp_parser_declarator.
	(cp_parser_explicit_instantiation): Likewise.
	(cp_parser_init_declarator): Likewise.
	(cp_parser_declarator): New parameter.  Use it.
	(cp_parser_direct_declarator): New parameter.  Use it to set
	local_variables_forbidden_p.  Adjust call to cp_parser_declarator.
	(cp_parser_type_id_1): Adjust call to cp_parser_declarator.
	(cp_parser_parameter_declaration): Likewise.
	(cp_parser_default_argument): Update the type of
	local_variables_forbidden_p.  Set it to LOCAL_VARS_AND_THIS_FORBIDDEN
	rather than true.
	(cp_parser_member_declaration): Tell cp_parser_declarator if we saw
	'static' or 'friend'.
	(cp_parser_exception_declaration): Adjust call to cp_parser_declarator.
	(cp_parser_late_parsing_default_args): Update the type of
	local_variables_forbidden_p.  Set it to LOCAL_VARS_AND_THIS_FORBIDDEN
	rather than true.
	(cp_parser_cache_defarg): Adjust call to cp_parser_declarator.
	(cp_parser_objc_class_ivars): Likewise.
	(cp_parser_objc_struct_declaration): Likewise.
	(cp_parser_omp_for_loop_init): Likewise.
	* parser.h (cp_parser): Change the type of local_variables_forbidden_p
	to unsigned char.
	(LOCAL_VARS_FORBIDDEN, LOCAL_VARS_AND_THIS_FORBIDDEN, THIS_FORBIDDEN):
	Define.

	* g++.dg/cpp0x/this1.C: New test.

From-SVN: r267731
parent 5a5474ba
2019-01-08 Marek Polacek <polacek@redhat.com>
PR c++/88548 - this accepted in static member functions.
* parser.c (cp_debug_parser): Adjust printing of
local_variables_forbidden_p.
(cp_parser_new): Set local_variables_forbidden_p to 0 rather than false.
(cp_parser_primary_expression): When checking
local_variables_forbidden_p, use THIS_FORBIDDEN or
LOCAL_VARS_FORBIDDEN.
(cp_parser_lambda_body): Update the type of
local_variables_forbidden_p. Set it to 0 rather than false.
(cp_parser_condition): Adjust call to cp_parser_declarator.
(cp_parser_explicit_instantiation): Likewise.
(cp_parser_init_declarator): Likewise.
(cp_parser_declarator): New parameter. Use it.
(cp_parser_direct_declarator): New parameter. Use it to set
local_variables_forbidden_p. Adjust call to cp_parser_declarator.
(cp_parser_type_id_1): Adjust call to cp_parser_declarator.
(cp_parser_parameter_declaration): Likewise.
(cp_parser_default_argument): Update the type of
local_variables_forbidden_p. Set it to LOCAL_VARS_AND_THIS_FORBIDDEN
rather than true.
(cp_parser_member_declaration): Tell cp_parser_declarator if we saw
'static' or 'friend'.
(cp_parser_exception_declaration): Adjust call to cp_parser_declarator.
(cp_parser_late_parsing_default_args): Update the type of
local_variables_forbidden_p. Set it to LOCAL_VARS_AND_THIS_FORBIDDEN
rather than true.
(cp_parser_cache_defarg): Adjust call to cp_parser_declarator.
(cp_parser_objc_class_ivars): Likewise.
(cp_parser_objc_struct_declaration): Likewise.
(cp_parser_omp_for_loop_init): Likewise.
* parser.h (cp_parser): Change the type of local_variables_forbidden_p
to unsigned char.
(LOCAL_VARS_FORBIDDEN, LOCAL_VARS_AND_THIS_FORBIDDEN, THIS_FORBIDDEN):
Define.
2019-01-08 Paolo Carlini <paolo.carlini@oracle.com>
* decl.c (start_decl): Improve permerror location.
......
......@@ -282,9 +282,12 @@ struct GTY(()) cp_parser {
been seen that makes the expression non-constant. */
bool non_integral_constant_expression_p;
/* TRUE if local variable names and `this' are forbidden in the
current context. */
bool local_variables_forbidden_p;
/* Used to track if local variable names and/or `this' are forbidden
in the current context. */
#define LOCAL_VARS_FORBIDDEN (1 << 0)
#define THIS_FORBIDDEN (1 << 1)
#define LOCAL_VARS_AND_THIS_FORBIDDEN (LOCAL_VARS_FORBIDDEN | THIS_FORBIDDEN)
unsigned char local_variables_forbidden_p;
/* TRUE if the declaration we are parsing is part of a
linkage-specification of the form `extern string-literal
......
2019-01-08 Marek Polacek <polacek@redhat.com>
PR c++/88548 - this accepted in static member functions.
* g++.dg/cpp0x/this1.C: New test.
2019-01-08 Martin Liska <mliska@suse.cz>
PR tree-optimization/88753
......
// PR c++/88548
// { dg-do compile { target c++11 } }
struct S1 {
int a;
auto m1 () -> decltype(this->a) { return 0; }
auto m2 () -> decltype(this) { return 0; }
void m3 () noexcept(noexcept(this->a)) { }
void m4 () noexcept(noexcept(this)) { }
static auto m5 () -> decltype(this->a) { return 0; } // { dg-error ".this. may not be used in this context" }
static auto m6 () -> decltype(this) { return 0; } // { dg-error ".this. may not be used in this context" }
static void m7 () noexcept(noexcept(this->a)) { } // { dg-error ".this. may not be used in this context" }
static void m8 () noexcept(noexcept(this)) { } // { dg-error ".this. may not be used in this context" }
};
template <typename T>
struct S2 {
static auto f1(T arg) -> decltype((arg));
};
struct S3 {
int a;
void f1 () noexcept(noexcept(a)) { }
static void f2() noexcept(noexcept(a)) { }
static auto f3() -> decltype(a);
static auto f4() -> decltype((a));
};
template<typename T>
class S4 {
T i;
friend int foo(const S4 &t) noexcept(noexcept(i)) { return t.i; }
};
void
test ()
{
S4<int> t;
foo(t);
}
struct S5 {
friend auto bar() -> decltype(this); // { dg-error ".this. may not be used in this context" }
auto bar2() -> decltype(this);
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment