From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 119605 invoked by alias); 19 Jul 2017 09:31:07 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 119587 invoked by uid 89); 19 Jul 2017 09:31:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-27.1 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_LOW,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=rock, FINAL, H*r:sk:static. X-HELO: mail-it0-f50.google.com Received: from mail-it0-f50.google.com (HELO mail-it0-f50.google.com) (209.85.214.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Jul 2017 09:31:04 +0000 Received: by mail-it0-f50.google.com with SMTP id a62so34088028itd.1 for ; Wed, 19 Jul 2017 02:31:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=GssZnrNJy7zTA33maQJC4YflYR5Odi403X9x3wdu0IE=; b=W+E+v4dMCxZqyRCfLvAXjFI14Mi7iO3tUdfZKqShRgrZPf9pOrdWGDumo5bdcP9x0c NtpOgw0D4SW6lNHH3qj1ZAMeudVqzbTbKWJuMBDomsNi6B86egKSYe+Nu6qjCvK1ensy upGjOF0IZlDkdX87UXoiBKasnTiO2I2P7m6vrNjvJLOWkqgYuLANHwxFUNwWY7JSqWwd oUTQCwpT8+yWuYztxGwecZVIzhc0Z+VITZih7DKIH0P+HruPlj7KKdZne3s9N9oLauGH vd/bNGwmMug/I69AZ+YSAVnprBtFZB92EccdGUfhwFD/C4QzYxOUbvMmk/ydZ8fUjAe0 RT+w== X-Gm-Message-State: AIVw111d8wF6TgHxDaVfNA5m2Sa602TPGQXjeNMAwKeXene3mwqGePOa A6FpXtxjU122UxyF X-Received: by 10.36.53.70 with SMTP id k67mr1323361ita.79.1500456662452; Wed, 19 Jul 2017 02:31:02 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (static.42.136.251.148.clients.your-server.de. [148.251.136.42]) by smtp.gmail.com with ESMTPSA id n65sm8249594itg.23.2017.07.19.02.30.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Jul 2017 02:30:53 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gcc-patches@gcc.gnu.org Cc: palves@redhat.com Subject: [PATCH] Add macro DISABLE_COPY_AND_ASSIGN Date: Wed, 19 Jul 2017 09:31:00 -0000 Message-Id: <1500456645-30359-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes X-SW-Source: 2017-07/txt/msg01134.txt.bz2 We have many classes that copy cotr and assignment operator are deleted in different projects, gcc, gdb and gold. So this patch adds a macro to do this, and replace these existing mechanical code with macro DISABLE_COPY_AND_ASSIGN. The patch was posted in gdb-patches, https://sourceware.org/ml/gdb-patches/2017-07/msg00254.html but we think it is better to put this macro in include/ansidecl.h so that other projects can use it too. Boostrapped on x86_64-linux-gnu. Is it OK? include: 2017-07-19 Yao Qi Pedro Alves * ansidecl.h (DISABLE_COPY_AND_ASSIGN): New macro. gcc/cp: 2017-07-19 Yao Qi * cp-tree.h (class ovl_iterator): Use DISABLE_COPY_AND_ASSIGN. * name-lookup.c (struct name_loopup): Likewise. gcc: 2017-07-19 Yao Qi * tree-ssa-scopedtables.h (class avail_exprs_stack): Use DISABLE_COPY_AND_ASSIGN. (class const_and_copies): Likewise. --- gcc/cp/cp-tree.h | 4 +--- gcc/cp/name-lookup.c | 3 +-- gcc/tree-ssa-scopedtables.h | 6 ++---- include/ansidecl.h | 19 +++++++++++++++++++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index abc9b65..9a45680 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -718,9 +718,7 @@ class ovl_iterator } private: - /* Do not duplicate. */ - ovl_iterator &operator= (const ovl_iterator &); - ovl_iterator (const ovl_iterator &); + DISABLE_COPY_AND_ASSIGN (ovl_iterator); public: operator bool () const diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index cd7428a..f80958d 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -194,8 +194,7 @@ public: } private: /* Uncopyable, unmovable, unassignable. I am a rock. */ - name_lookup (const name_lookup &); - name_lookup &operator= (const name_lookup &); + DISABLE_COPY_AND_ASSIGN (name_lookup); protected: static bool seen_p (tree scope) diff --git a/gcc/tree-ssa-scopedtables.h b/gcc/tree-ssa-scopedtables.h index df304ae..692da8a 100644 --- a/gcc/tree-ssa-scopedtables.h +++ b/gcc/tree-ssa-scopedtables.h @@ -158,8 +158,7 @@ class avail_exprs_stack /* We do not allow copying this object or initializing one from another. */ - avail_exprs_stack& operator= (const avail_exprs_stack&); - avail_exprs_stack (class avail_exprs_stack &); + DISABLE_COPY_AND_ASSIGN (avail_exprs_stack); }; /* This class defines an unwindable const/copy equivalence table @@ -197,8 +196,7 @@ class const_and_copies private: vec m_stack; - const_and_copies& operator= (const const_and_copies&); - const_and_copies (class const_and_copies &); + DISABLE_COPY_AND_ASSIGN (const_and_copies); }; void initialize_expr_from_cond (tree cond, struct hashable_expr *expr); diff --git a/include/ansidecl.h b/include/ansidecl.h index f6e1761..796f744 100644 --- a/include/ansidecl.h +++ b/include/ansidecl.h @@ -354,6 +354,25 @@ So instead we use the macro below and test it against specific values. */ # define FINAL #endif +/* A macro to disable the copy constructor and assignment operator. + When building with C++11 and above, the methods are explicitly + deleted, causing a compile-time error if something tries to copy. + For C++03, this just declares the methods, causing a link-time + error if the methods end up called (assuming you don't + define them). For C++03, for best results, place the macro + under the private: access specifier, so that most attempts at + copy are caught at compile-time. */ + +#if __cplusplus >= 201103 +#define DISABLE_COPY_AND_ASSIGN(TYPE) \ + TYPE (const TYPE&) = delete; \ + void operator= (const TYPE &) = delete + #else +#define DISABLE_COPY_AND_ASSIGN(TYPE) \ + TYPE (const TYPE&); \ + void operator= (const TYPE &) +#endif /* __cplusplus >= 201103 */ + #ifdef __cplusplus } #endif -- 1.9.1