From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B8CA83858C42 for ; Wed, 22 May 2024 15:42:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B8CA83858C42 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B8CA83858C42 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716392524; cv=none; b=ut+cURqkKa4kXw+GBgi0wsVQucdWGnQd2/4V0hMHdwsSIGyn0afV60y6sdAegkuWasKHhzWzapNFoNGUZc7+gszkbrcaiq8HPVULYy6IWynmhcKSQI66qynI6DCGiPkax5gPkOIS/a13y7LjYXkLYXUXFoJ7HwF17Zs8HT/wz8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716392524; c=relaxed/simple; bh=Gk8G00/KcnC7cOW3UrM9v9fiAscJGdspMskS/vYP5R0=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=vWSaJ0M8UwnC+kDUUQ3aN0vJOU3w+ZoeoHxVk/b4xtZddAn+L5Ulu33vu1azEqpsaPr+yS5Qg+WmWksaPUkVjLhpUtiMwvyFoppfSzM5fd6PS7D3MN7D0hjI/1BVk6Rnq0e2+QTlkKn/K+fHHywupG2xYmJwe/M1EiEcBzqsI0s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716392522; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7NTXayhT8D3dbQP3Vy6hkXVpJ6BE2RRLPh+jFsOCoS0=; b=SVfkz05XZdz6RzgLtrrIIMumM8HucMZjMUXCXypb6Tw9uKcG+44IljuBQ2OXRtLARh2f6V gg7O8xnIQO2BlwmjJT35wPbJh21lsqe9flUI0xh7J8/lYw4EE/PWnOfwpq3tnQdYXuOOn1 J946+dorPlBvMrASfDYRz4d3FetKS80= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-115-hYrE-NdEP2-0Z5LUd5koCQ-1; Wed, 22 May 2024 11:41:58 -0400 X-MC-Unique: hYrE-NdEP2-0Z5LUd5koCQ-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-792ba069a97so1889747485a.0 for ; Wed, 22 May 2024 08:41:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716392517; x=1716997317; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7NTXayhT8D3dbQP3Vy6hkXVpJ6BE2RRLPh+jFsOCoS0=; b=PqsF87QB6uNciewJz1QXl26DhOFv1ZGSZjzcqn2I15rDVuAaWkZMM1RVOJ2n6A+sPp 0DceBjxbouLYOEs8kgHSYMrLveDKMx6o0UkV+CW4ZmTbzCe4BLV0OZUkIlKAXWfuJtvI MQ+MnrHUXgQu5G2e8CPvzjeO0eAxaCW566qVTgt5Y74kAERRaXHNh/fnKor2IkymRaGu caAN+CKO2cQZdOv7cRpW83SmE7o7Sp/Ix9wT6y/n+zX+birkbtUV/3nczTzKLYXTaLM1 jOc4R6s9RUBXJgYD2A5yxwpailJ7bNhAjM6MsvYrHg2Yhf95JO6Tw6152SmtQzfgUMXe WwNw== X-Forwarded-Encrypted: i=1; AJvYcCXp2+aMqeoVsTg+f2efjdMkVTHBiVrUGW66rDl3NeA3YP7v8S7VRRczeLWndrJ8Kumk8br0nfrCnUznSMtjIKeyYn+HaLQ6KQ== X-Gm-Message-State: AOJu0YyTUD1Ec1LsSuVy2POvs4DQjGCrCrDIuZUIbMdhWBHV31Vx+Lmn YdxuzrFPhLbqwGq0Bp84JTj+K9qGg2kwIinqZL+6Uq5tnnRxqmUqAtZUDC0XMC3hoZZ9Qy4FaZ2 OS+xsJRPEW/6mgVltJPop+K5VqeX4uWuQrB3e+J2zXntdHA8lz0Eeu14HLKuAntY= X-Received: by 2002:a05:620a:4ce:b0:78d:6182:fa35 with SMTP id af79cd13be357-794994b1743mr225270985a.53.1716392517168; Wed, 22 May 2024 08:41:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHdJJbttHdJ3uulbIMEncJUI53p0ovfy7YoLb6b3hTKQczzq/H/gaonoJJM0Sb4I8D0pEfyVw== X-Received: by 2002:a05:620a:4ce:b0:78d:6182:fa35 with SMTP id af79cd13be357-794994b1743mr225269285a.53.1716392516718; Wed, 22 May 2024 08:41:56 -0700 (PDT) Received: from [172.27.123.100] (static-173-48-226-51.bstnma.fios.verizon.net. [173.48.226.51]) by smtp.gmail.com with ESMTPSA id af79cd13be357-792bf33b36csm1396839285a.129.2024.05.22.08.41.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 May 2024 08:41:56 -0700 (PDT) Message-ID: Date: Wed, 22 May 2024 11:41:55 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] Fix auto deduction for template specialization scopes [114915]. To: Seyed Sajad Kahani , gcc-patches@gcc.gnu.org References: <20240501225217.59069-1-sska1377@gmail.com> From: Jason Merrill In-Reply-To: <20240501225217.59069-1-sska1377@gmail.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Thanks for the patch! Please review https://gcc.gnu.org/contribute.html for more details of the format patches should have. In particular, you don't seem to have a copyright assignment on file with the FSF, so you'll need to either do that or certify that the contribution is under the DCO. Also, you need a component tag (c++:) in the subject line, and ChangeLog entries in the commit message. Note what contribute.html says about git gcc-commit-mklog, which makes that a lot simpler. On 5/1/24 18:52, Seyed Sajad Kahani wrote: > When deducing auto for `adc_return_type`, `adc_variable_type`, and `adc_decomp_type` contexts (at the usage time), we try to resolve the outermost template arguments to be used for satisfaction. This is done by one of the following, depending on the scope: > > 1. Checking the `DECL_TEMPLATE_INFO` of the current function scope and extracting DECL_TI_ARGS from it for function scope deductions (pt.cc:31236). > 2. Checking the `DECL_TEMPLATE_INFO` of the declaration (alongside with other conditions) for non-function scope variable declaration deductions (decl.cc:8527). > > Then, we do not retrieve the deeper layers of the template arguments; instead, we fill the missing levels with dummy levels (pt.cc:31260). > > The problem (that is shown in PR114915) is that we do not consider the case where the deduction happens in a template specialization scope. In this case, the type is not dependent on the outermost template arguments (which are the specialization arguments). Yet, we still resolve the outermost template arguments, and then the number of layers in the template arguments exceeds the number of levels in the type. This causes the missing levels to be negative. This leads to the rejection of valid code and ICEs (like segfault) in the release mode. In the debug mode, it is possible to show as an assertion failure (when creating a tree_vec with a negative size). > The code that generates the issue is added to the test suite as `g++.dg/cpp2a/concepts-placeholder14.C`. This testcase could use more cases, like variable template specialization (both full and partial) and member functions where not all enclosing classes are fully specialized. > This patch fixes the issue by checking that the template usage, whose arguments are going to be used for satisfaction, is not a partial or explicit specialization (and therefore it is an implicit or explicit instantiation). This check is done in the two only places that affect the `outer_targs` for the mentioned contexts. It seems like we want a function to use instead of DECL_TI_ARGS to get the args for parameters that are actually in scope in the definition that we're substituting into. In the case of a full specialization, that would be NULL_TREE, but it's more complicated for partial specializations. This function should probably go after outer_template_args in pt.cc. > One might ask why this is not implemented as a simple `missing_level > 0` check. The reason is that the recovery from the negative `missing_levels` will not be easy, and it is not clear how to recover from it. Therefore, it is better to prevent it from happening. But you still have that check in the patch. Would it be better as an assert? Thanks, Jason