From dd9ba663b42ced4a1520746f03f898f8f97ce409 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 11 Nov 2012 11:24:12 -0800 Subject: [PATCH] Bug 394024 - Template resolution problem with unsigned int non type parameter. --- .../parser/tests/ast2/AST2TemplateTests.java | 14 ++++++++++++-- .../core/dom/parser/cpp/CPPBasicType.java | 16 +++++++++++----- .../cpp/semantics/TemplateArgumentDeduction.java | 7 +++++-- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 36398f1d018..8a5cd047e16 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -4205,8 +4205,18 @@ public class AST2TemplateTests extends AST2BaseTest { // S(a); // } public void testFunctionTemplateWithArrayReferenceParameter_269926() throws Exception { - final String code = getAboveComment(); - parseAndCheckBindings(code); + parseAndCheckBindings(); + } + + // template + // void S(int (&array)[N]); + // + // int a[1]; + // void test() { + // S(a); + // } + public void testFunctionTemplateWithArrayReferenceParameter_394024() throws Exception { + parseAndCheckBindings(); } // template diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java index 56aa33d361f..baf5e299e3c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * Andrew Niefer (IBM Corporation) - initial API and implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -31,6 +32,7 @@ import org.eclipse.core.runtime.CoreException; */ public class CPPBasicType implements ICPPBasicType, ISerializableType { private static final int FROM_STRING_LITERAL = 1 << 31; + public static final int UNSPECIFIED_MODIFIERS = 1 << 30; public static final CPPBasicType BOOLEAN = new CPPBasicType(Kind.eBoolean, 0, null); public static final CPPBasicType NULL_PTR = new CPPBasicType(Kind.eNullPtr, 0, null); @@ -119,16 +121,20 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { if (!(object instanceof ICPPBasicType)) return false; - ICPPBasicType t = (ICPPBasicType) object; - if (fKind != t.getKind()) + ICPPBasicType other = (ICPPBasicType) object; + if (fKind != other.getKind()) return false; int modifiers = getModifiers(); + int otherModifiers = other.getModifiers(); + if ((modifiers & UNSPECIFIED_MODIFIERS) != 0 || (otherModifiers & UNSPECIFIED_MODIFIERS) != 0) { + return true; + } if (fKind == Kind.eInt) { // Signed int and int are equivalent. - return (modifiers & ~IS_SIGNED) == (t.getModifiers() & ~IS_SIGNED); + return (modifiers & ~IS_SIGNED) == (otherModifiers & ~IS_SIGNED); } - return modifiers == t.getModifiers(); + return modifiers == otherModifiers; } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java index c933dbdb11a..cd8ebac54a2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java @@ -737,8 +737,11 @@ public class TemplateArgumentDeduction { if (parID >= 0) { ICPPTemplateArgument old= fDeducedArgs.getArgument(parID, fPackOffset); if (old == null) { - if (!deduce(parID, - new CPPTemplateNonTypeArgument(as, new CPPBasicType(ICPPBasicType.Kind.eInt, 0)))) { + // Template-argument deduced from an array bound may be of any integral + // type (14.8.2.5 - 17). + CPPBasicType wildcardIntegralType = + new CPPBasicType(ICPPBasicType.Kind.eInt, CPPBasicType.UNSPECIFIED_MODIFIERS); + if (!deduce(parID, new CPPTemplateNonTypeArgument(as, wildcardIntegralType))) { return false; } } else if (!as.equals(old.getNonTypeValue())) {