
92 Wis.2d 645 (1979)
285 N.W.2d 745
Edna HALKER, Plaintiff-Respondent,
v.
Eugene A. HALKER, Defendant-Appellant.
No. 77-059.
Supreme Court of Wisconsin.
Submitted on briefs November 7, 1979.
Decided December 4, 1979.
*646 For the appellant the cause was submitted on the briefs of Richard F. Wartman, Keith W. Dallenbach and Wartman, Wartman & Swanson, S.C., attorneys, of Ashland; and Richard Tinkham and Tinkham, Smith, Bliss, Patterson & Richards, of counsel, of Wausau.
For the respondent the cause was submitted on the brief of De Bardeleben & Snyder of Park Falls.
COFFEY, J.
This is an appeal from an order of the County Court of Ashland County dismissing Eugene A. Halker's (hereinafter the defendant) counterclaim for an annulment of his marriage to Edna Halker on the grounds that he failed to state a claim upon which relief could be granted.
The trial court record establishes that the defendant filed for a divorce on February 17, 1971, from his first wife, Laura, in the Second Judicial District Court of Washoe County, Nevada. The defendant resided in the state of Nevada from December 27, 1970 until June 4, 1971, when a decree of divorce from his first wife was entered. After the entry of the Nevada divorce decree the defendant returned to his home in Ashland County, Wisconsin. During the period of time the defendant lived in Nevada, fulfilling the residence requirement for his divorce, he also maintained a home and business in Ashland County, Wisconsin. Mrs. Edna Halker, the defendant's *647 second wife and the plaintiff-respondent in this action (hereinafter the plaintiff), also obtained a divorce from her then present husband in the state of Michigan at approximately the same time. The plaintiff resided with the defendant for a period of time in Nevada while he was obtaining his divorce from his first wife.
Following their respective divorces from their spouses the parties applied for a marriage license in Duluth, Minnesota, without success early in the month of July, 1971. The record is silent as to why the marriage license was refused. Shortly thereafter they reapplied for and received a marriage license in Ironwood, Michigan, listing their residence as Ashland, Wisconsin. They were married on July 17, 1971, in Ironwood, Michigan, and lived together as man and wife for approximately four and one-half years.
On June 24, 1976 the plaintiff filed the present action for legal separation from the defendant. In the complaint the plaintiff alleged that the defendant had treated her in a cruel and inhuman manner so as to have a detrimental effect on her mental and physical health. The defendant denied the allegation of cruel and inhuman treatment and, as an affirmative defense, alleged that their marriage was void from its inception as they failed to comply with the 6 month waiting period requirement after obtaining divorces from their spouses, in violation of sec. 245.03, (2), Stats.[1] Furthermore, the defendant claimed the marriage was "never validated" because both parties entered the marriage in bad faith.
The plaintiff on April 4, 1977, moved for an order dismissing the defendant's counterclaim because it failed to *648 state a claim upon which relief can be granted. The trial court in a written opinion held:
"It is concluded that the plaintiffs [sic] marriage to the defendant was voidable and not void and that the impediment to the marriage was removed when the statutory six month period lapsed after the date of respective decrees of divorce of the parties hereto. The voidable marriage then became a valid marriage.
"The counterclaim of the defendant must be dismissed."
The trial court dismissed the defendant's counterclaim for the following reasons:
". . . that the defendant was well aware of the existence of the impediment at the time of the marriage considering the fact that he left the State of Wisconsin to obtain a divorce and then went into a second and third state in an attempt to consummate the marriage. The plaintiff, on the other hand, obtained her divorce in the State of Michigan and remarried in the same state. Her divorce was final on the date of the decree with no waiting period for remarriage required. It is true that the plaintiff was aware and was evidently with the defendant when he obtained his divorce in Nevada and when he attempted to obtain a marriage license in the State of Minnesota. The Court must assume and does, that the defendant was the prime movant in seeking a license to marry and that the plaintiff accepted arrangements as made by the defendant. At the time a license was granted in Michigan, after a denial in the State of Minnesota, there was reason to believe that the plaintiff in good faith accepted the marriage contract as valid, in that she had been divorced in Michigan and married in the same State, under a license issued by Michigan authorities, notwithstanding that the fine print on the reverse of the application alluded in some respect to former divorce actions which may not have fully ripened into a final judgment.
"The Court has and does find in this case that there is evidence to support a finding of good faith on the part of the plaintiff in believing that the Michigan marriage was valid. The knowledge of the defendant in *649 relating to the impediment is not necessarily imputed to the plaintiff."
In essence, the court determined that Mrs. Halker had entered the marriage in good faith but that Mr. Halker entered into the marriage contract with ". . . total, knowledgeable and willful disregard of the law relating to his remarriage." Alternatively, the trial court ruled the parties' marriage should be sustained on equitable considerations ". . . without a finding of good faith on the part of either of the parties. . . .", pursuant to the court's rationale in Smith v. Smith, 52 Wis.2d 262, 190 N.W.2d 174 (1971).
On May 12, 1977, an order was entered dismissing the defendant's counterclaim on the grounds that it failed to state a claim upon which relief can be granted. From this order the defendant has appealed.
Issue:
Did the trial court err in dismissing the defendant's counterclaim for annulment for failure to state a claim upon which relief can be granted?
[1, 2]
A motion to dismiss for failure to state a claim upon which relief can be granted under sec. 802.06 (2), Stats.,[2]*650 serves the same function as a demurrer under the former rules of civil procedure and our court has ruled that a complaint or counterclaim is entitled to all reasonable inferences in its favor. Thus, the trial court, when ruling on a demurrer or a motion to dismiss a complaint or counterclaim should liberally construe the complaint or counterclaim with a view to achieving substantial justice. Riedy v. Sperry, 83 Wis.2d 158, 166, 265 N.W.2d 475 (1978). In Wilson v. Continental Insurance Cos., 87 Wis. 2d 310, 274 N.W.2d 679 (1979) this court held that: ". . . a motion to dismiss under sec. 802.06 (2) (f), Stats., usually will be granted only when it is quite clear that under no conditions can the plaintiff recover." Id. at 317. Therefore, if the defendant's counterclaim had any merit it should not have been dismissed.
The defendant in his counterclaim requests an annulment based on the fact that his marriage to the plaintiff was invalid from the beginning because they didn't wait the necessary 6 months after obtaining their divorces from their prior spouses before marrying, in violation of sec. 245.03, Stats. The defendant also contends that their marriage was never subsequently validated and therefore remained unlawful. Sec. 247.02 (9), Stats. *651 1975, provides that one of the grounds for annulment is that the "marriage is prohibited or declared void under ch. 245. . . ." If the parties' marriage was void and not validated then the defendant's counterclaim was proper and the trial court erred in dismissing the counterclaim for failure to state a claim upon which relief can be granted. However, if the marriage was subsequently validated then the defendant's counterclaim for annulment has no basis in law and therefore was properly dismissed.
In Wisconsin there are two ways an otherwise invalid marriage may be subsequently validated:
(1) pursuant to sec. 245.24, Stats.; or
(2) pursuant to the equitable principles set forth in Smith v. Smith, supra.
The trial court ruled in the present case that the marriage had been validated pursuant to either sec. 245.24, Stats., or Smith v. Smith.
[3]
Sec. 245.24, Stats., allows a subsequent invalid marriage to become valid provided that:
1. the second marriage was entered into by one of the parties in good faith believing either:
(a) that the former husband or wife was dead; or
(b) that the former marriage had been annulled or dissolved by divorce; or
(c) if either spouse is without knowledge of the other party's former marriage; and
2. after the impediment to the second marriage is removed, the parties to the contract continue to live together as husband and wife and one of the parties complies with the good faith requirement.
[4]
There is no question that Mr. and Mrs. Halker continued to live together as husband and wife for approximately 4 years after the 6 month waiting period *652 problem was resolved and thus the impediment to their marriage had been removed.
Next we reach the question as to whether the plaintiff entered into the marriage in good faith, as the defendant in his counterclaim has alleged that both parties entered into the marriage contract in bad faith and thus their marriage could not have been validated pursuant to sec. 245.24, Stats.
[5]
Prior to Smith v. Smith, supra, this court had relaxed the stringent common law rule, that unlawful marriages are null and void, when holding that previously void marriages would now be considered voidable in situations where the impediment to the second marriage was removed. This liberalization of the strict common law rule thus allowed Wisconsin courts an opportunity to exercise discretion in granting annulment decrees. Id. at 267. In Davidson v. Davidson, 35 Wis.2d 401, 151 N.W.2d 53 (1967) the court held that:
"A definition of voidable and void marriage which will closely fit modern conditions is that a marriage may be considered voidable although prohibited by law when it is possible, under any circumstances, for the parties to contract the marriage, or subsequently to ratify it, while it should be considered void if it is impossible for them under the law to contract it, and if it is impossible for them subsequently by any conduct to ratify it, and if the statute expressly declares that the marriage is void." Id. at 407, quoting 35 Am. Jur., Marriage, p. 212, §46.
The Smith court relied on the Davidson holding and stated that:
"(1) A marriage made void under secs. 245.002 (3), 245.03(1) and 245.21, Stats., is not void but voidable in certain situations when an impediment to the marriage is removed.
*653 "(2) It is in the public interest to maintain a marriage relationship. (Sec. 245.001 (2), Stats.)"[3]Id. at 269.
In Smith the plaintiff-wife sought to have her marriage to the defendant-husband annulled because she claimed her prior husband was still living at the time of her marriage to the defendant. The court ruled that the parties in the Smith case did not meet the statutory requirements of sec. 245.24 for validation of their marriage because:
1. the parties failed to live together after the impediment to their marriage had been removed, i.e., the death of her husband; and
2. there was some evidence that both parties entered into the marriage contract with knowledge that there existed an impediment, a prior living spouse, and therefore they failed to comply with the good faith requirement of sec. 245.24, Stats.
In Smith, even though the parties' marriage had not been validated in compliance with the requirements of sec. 245.24, Stats., the court nevertheless held the marriage voidable, not void. Furthermore, the court held *654 that the marriage was subsequently validated with the death of the plaintiff's first husband, thus removing the impediment to the marriage. With this ruling the court recognized and adopted a non-statutory form of validating what was previously considered an unlawful marriage. The court dismissed the plaintiff's cause of action for annulment because she did not satisfy the equitable doctrine of "clean hands" but validated the marriage finding it to be in the public interest to maintain the marital relationship.
In furtherance of the public interest doctrine our legislature has enacted sec. 245.001 (2), Stats., which reads in part as follows:
"It is the intent of chs. 245 to 248 to promote the stability and best interests of marriage and the family. Marriage is the institution that is the foundation of the family and of society. Its stability is basic to morality and civilization and of vital interest to society and the state. The consequences of the marriage contract are more significant to society than those of other contracts, and the public interest must be taken into account always. . . ."
The court in Smith recognized that equitable doctrines, such as the "clean hands" doctrine, should generally ". . . not be invoked in contravention of the public policy of the state. . . ." Smith v. Smith, supra at 269, quoting from Davidson v. Davidson, supra at 410. However, the court held that the "clean hands" doctrine does not contravene or offend, but rather "complements" the statutory public policy of upholding and maintaining the marital relationship, whenever possible, as expressed in sec. 245.001 (2), Stats. Smith v. Smith, supra at 270. Therefore, validating the marriage in Smith was consistent with the statutory public policy of maintaining and promoting the marriage relationship.
Recently the court of appeals, in Corning v. Carriers Ins. Co., 88 Wis.2d 17, 276 N.W.2d 310 (Ct. App. 1979), *655 confirmed the holding in Smith that a second marriage may be validated under common law even though the requirements of sec. 245.24, Stats., have not been met.
[6]
The factual situation in the present case is similar to that of Smith. The defendant, like Smith, requested that his marriage to the plaintiff be annulled on the grounds that their marriage was void from its inception as both parties entered into the marriage contract without fulfilling the 6 month waiting period after their divorces. In fact, the defendant admitted in his counterclaim that he entered the marriage in bad faith. Further, he alleged that the marriage was not subsequently validated in accordance with sec. 245.24, Stats. Thus, the equitable doctrine of "clean hands" precludes the defendant from obtaining an annulment of his marriage to the plaintiff. Therefore, in light of Smith v. Smith, supra, and the requirements of the "clean hands" doctrine, we uphold the court's dismissal of the counterclaim and hold that the defendant in this case was not entitled to have his marriage annulled. Furthermore, in this case, we hold that the defendant's marriage to the plaintiff, which was originally voidable because of the parties' failure to comply with the 6 month waiting period before remarrying, became valid upon removal of the impediment to the marriage. Thus, the marriage contract was ratified as they continued to live together as husband and wife for approximately 4 more years. Therefore, we concur with the trial court's judgment granting the plaintiff's motion to dismiss the defendant's counterclaim for failure to state a claim upon which relief can be granted.
By the Court.Order affirmed.
NOTES
[1]  "Sec. 245.03 Who shall not marry; divorced persons. (1) . . .

"(2) It is unlawful for any person, who is or has been a party to an action for divorce in any court in this state, or elsewhere, to marry again until 6 months after judgment of divorce is granted, and the marriage of any such person solemnized before the expiration of 6 months from the date of the granting of judgment of divorce shall be void."
[2]  "802.06 Defenses and objection; when and how presented; by pleading or motion; motion for judgment on the pleadings.

"(2) HOW PRESENTED. Every defense, in law or fact, except the defense of improper venue, to a claim for relief in any pleading, whether a claim, counterclaim, cross-claim, or 3rd party claim shall be asserted in the responsive pleading thereto if one is required, except that the following defenses may at the option of the pleader be made by motion: (a) lack of capacity to sue or be sued, (b) lack of jurisdiction over the subject matter, (c) lack of jurisdiction over the person or res, (d) insufficiency of summons or process, (e) untimeliness or insufficiency of service of summons or process, (f) failure to state a claim upon which relief can be granted, (g) failure to join a party under s. 803.03, (h) res judicata, (i) statute of limitations, (j) another action pending between the same parties for the same cause. A motion making any of these defenses shall be made before pleading if a further pleading is permitted. Objection to venue shall be made in accordance with s. 801.53. If a pleading sets forth a claim for relief to which the adverse party is not required to serve a responsive pleading, the adverse party may assert at the trial any defense in law or fact to that claim for relief. If on a motion asserting the defense described in (f) to dismiss for failure of the pleading to state a claim upon which relief can be granted, or on a motion asserting the defenses described in (h) or (i), matters outside of the pleadings are presented to and not excluded by the court, the motion shall be treated as one for summary judgment and disposed of as provided in s. 802.08, and all parties shall be given reasonable opportunity to present all material made pertinent to such a motion by s. 802.08."
[3]  "245.001 Title, intent and construction of chapters 245 to 248. (1) TITLE. Chapters 245 to 248 may be cited as "The Family Code".

"(2) INTENT. It is the intent of chs. 245 to 248 to promote the stability and best interests of marriage and the family. Marriage is the institution that is the foundation of the family and of society. Its stability is basic to morality and civilization and of vital interest to society and the state. The consequences of the marriage contract are more significant to society than those of other contracts, and the public interest must be taken into account always. The seriousness of marriage makes adequate premarital counseling and education for family living highly desirable and courses thereon are urged upon all persons contemplating marriage. The impairment or dissolution of the marriage relation generally results in injury to the public wholly apart from the effect upon the parties immediately concerned."
