Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 399592

Summary: Template Argument Deduction throws AssertionErrors (Regression)
Product: [Tools] CDT Reporter: Markus Schorn <mschorn.eclipse>
Component: cdt-parserAssignee: Sergey Prigogin <eclipse.sprigogin>
Status: RESOLVED FIXED QA Contact: Markus Schorn <mschorn.eclipse>
Severity: normal    
Priority: P3 CC: cdtdoug, eclipse.sprigogin, mober.at+eclipse, zeratul976
Version: 8.2   
Target Milestone: 8.1.2   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Markus Schorn CLA 2013-01-31 04:29:04 EST
When you run the JUnit tests with -ea (as you always should do) the following test cases fail:

ASTCPPSpecDefectTests.test692_partialOrdering
AST2TemplateTests.testVariadicTemplateExamples_280909n
AST2TemplateTests.testRecursiveVariadicTemplate_397828
AST2CPPSpecTest.test14_8_2_4s21

The fact that the assertion fails indicates that the original logic of the template argument deduction is broken.

Stack trace is:
java.lang.AssertionError
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.TemplateArgumentDeduction.incPackOffset(TemplateArgumentDeduction.java:713)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.TemplateArgumentDeduction.fromTemplateArguments(TemplateArgumentDeduction.java:625)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates.selectSpecialization(CPPTemplates.java:2082)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates.instantiate(CPPTemplates.java:262)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates.createBinding(CPPTemplates.java:729)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTemplateId.createIntermediateBinding(CPPASTTemplateId.java:128)
Comment 1 Nathan Ridge CLA 2013-02-04 11:38:54 EST
This may have been broken by one of my patches. I will look into it.

How do you run the tests with -ea? So far the way I've run them is by right-clicking on a test suite (like DOMParserTestSuite) in Eclipse and selecting Run As -> JUnit Plug-in Test.
Comment 2 Martin Oberhuber CLA 2013-02-04 12:14:35 EST
Choose Run > Debug... to edit the Launch Configuration which was created by your "Run As..." action. On its "Arguments" tab under "VM Arguments" add "-ea" .
Comment 3 Sergey Prigogin CLA 2013-02-04 14:23:16 EST
I've pushed a proposed fix to https://git.eclipse.org/r/#/c/10165/.
Comment 4 Nathan Ridge CLA 2013-02-05 03:37:04 EST
(In reply to comment #3)
> I've pushed a proposed fix to https://git.eclipse.org/r/#/c/10165/.

I think the following patch is sufficient to fix the problem:

--- 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
@@ -622,7 +622,9 @@ public class TemplateArgumentDeduction {
                                        if (!deduct.fromTemplateArgument(pattern, a[i], point)) {
                                                return false;
                                        }
-                                       deduct.incPackOffset();
+                                       if (i != a.length - 1) {
+                                               deduct.incPackOffset();
+                                       }
                                }
                                break;
                        } else {
Comment 5 Sergey Prigogin CLA 2013-02-05 11:56:09 EST
(In reply to comment #4)
> (In reply to comment #3)
> > I've pushed a proposed fix to https://git.eclipse.org/r/#/c/10165/.
> 
> I think the following patch is sufficient to fix the problem:
> 
> ---
> 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
> @@ -622,7 +622,9 @@ public class TemplateArgumentDeduction {
>                                         if
> (!deduct.fromTemplateArgument(pattern, a[i], point)) {
>                                                 return false;
>                                         }
> -                                       deduct.incPackOffset();
> +                                       if (i != a.length - 1) {
> +                                               deduct.incPackOffset();
> +                                       }
>                                 }
>                                 break;
>                         } else {

This was my first idea, but I discarded it. Imagine for a second that due to some bug deduct.fromTemplateArgument is called again after "if (i != a.length - 1) { deduct.incPackOffset(); }". If we want the assertion to catch such situation, it should be moved from incPackOffset to fromTemplateArgument how it is done in https://git.eclipse.org/r/#/c/10165.
Comment 7 CDT Genie CLA 2013-02-27 12:15:39 EST
*** cdt git genie on behalf of Sergey Prigogin ***

    Bug 399592 - Template Argument Deduction throws AssertionErrors
    Change-Id: I891a0ea21e54c2e0a4969a351b3366859525dcd4
    Reviewed-on: <a  href="https://git.eclipse.org/r/10165">https://git.eclipse.org/r/10165</a>
    Reviewed-by: Sergey Prigogin &lt;eclipse.sprigogin@xxxxxxxxx&gt;
    IP-Clean: Sergey Prigogin &lt;eclipse.sprigogin@xxxxxxxxx&gt;
    Tested-by: Sergey Prigogin &lt;eclipse.sprigogin@xxxxxxxxx&gt;

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=fd96243c704c11eda1627f4a7802ba0837956728